URLConnection getHeaderFields Example

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


URLConnection class getHeaderFields example. public Map

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

import java.net.*;
import java.util.*;

public class GetHeaderFields {

    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);

        Map map = connection.getHeaderFields();
        Set set = map.entrySet();
        
        Iterator iterator = set.iterator();
        while (iterator.hasNext()) {
            System.out.println(iterator.next());
        }
    }
}

Output
null=[HTTP/1.0 200 OK]
Date=[Fri, 27 Jun 2008 11:07:11 GMT]
Expires=[-1]
Set-Cookie=[PREF=ID=c93ce081df704bda:TM=1214564831:LM=1214564831:S=ZDBt6BUzC6lwO2gB; expires=Sun, 27-Jun-2010 11:07:11 GMT; path=/; domain=.google.co.in]
Content-Type=[text/html; charset=ISO-8859-1]
Server=[gws]
X-Cache=[MISS from SquidNT]
Cache-Control=[private, max-age=0]
Proxy-Connection=[close]

Post Comment
Name:
E-mail:
Contact no :
Comments:
  Refresh Image
Verify Image:
 
 
Your Comment's
 
 
 

HOME | COPYRIGHT | CONTACT US