Nov 19

The Proxy class can be used specify proxy details at the connection level.

SocketAddress addr = new InetSocketAddress("proxy.objects.com", 88);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
URL url = new URL("http://java.sun.com/");
URConnection conn = url.openConnection(proxy);

written by objects \\ tags: , ,

Oct 01

Cookies are specified in the response header keyed on ‘Set-Cookie’ so the getHeaderFields() method of URLConnection can be used to retrieve them.


URLConnection conn = new url.openConnection();
Map<String,List<String>> headers = conn.getHeaderFields();
List<String> cookies = headers.get("Set-Cookie");
for (String cookie: cookies)
{
   System.out.println(cookie);
} 

written by objects \\ tags: ,