News:

Choose a design and let our professionals help you build a successful website   - ITAcumens

Main Menu

URLConnection getHeaderFieldKey Example

Started by VelMurugan, Dec 19, 2008, 09:36 PM

Previous topic - Next topic

VelMurugan

URLConnection getHeaderFieldKey Example

URLConnection class getHeaderFieldKey example. This example shows you how to use getHeaderFieldKey method.

URLConnection class getHeaderFieldKey example. public String getHeaderFieldKey(int n) Returns the key for the nth header field. It returns null if there are fewer than n+1 fields.

Here is the code

/*
* @ # GetHeaderFieldKey.java
* A class repersenting use to GetHeaderFieldKey
* method of URLConnection class in java.net package
* version 23 June 2008
* author Rose India
*/

import java.net.*;

public class GetHeaderFieldKey {

    public static void main(String args[]) throws Exception {

        SocketAddress socketAddress =
                new InetSocketAddress("192.168.10.80", 9090);
        Proxy proxy = new Proxy(Proxy.Type.HTTP, socketAddress);

        URL url = new URL("http://google.com");
        URLConnection connection = url.openConnection(proxy);
        int i = 1;
        while (connection.getHeaderFieldKey(i) != null) {
            System.out.println("Header Field Key " +
                    connection.getHeaderFieldKey(i));
            i++;
        }
    }
}


Output
Quote
Header Field Key Cache-Control
Header Field Key Date
Header Field Key Expires
Header Field Key Content-Type
Header Field Key Set-Cookie
Header Field Key Server

Header Field Key X-Cache
Header Field Key Proxy-Connection

Source : codingdiary