Albretch,
On Fri, Jan 14, 2011 at 22:00, Albretch Mueller <[email protected]> wrote:
>
> // __
> String aURL = "http://www.google.com/"
> HttpClient httpclient = new DefaultHttpClient();
> HttpGet httpget = new HttpGet(aURL);
> System.out.println("executing request " + httpget.getURI());
> // __
> HttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1,
> HttpStatus.SC_OK, "OK");
You are creating a new response object, and not one received from the
URL above. Instead of the statement above, try:
HttpResponse response = httpclient.execute(httpget);
> System.out.println(response.getProtocolVersion());
> System.out.println(response.getStatusLine().getStatusCode());
> System.out.println(response.getStatusLine().getReasonPhrase());
> System.out.println(response.getStatusLine().toString());
> Header[] Hdrs = response.getAllHeaders();
> System.out.println("// __ Hdrs.length: |" + Hdrs.length + "|");
> httpclient.getConnectionManager().shutdown();
> ~
> you get:
> ~
> HTTP/1.1
> 200
> OK
> HTTP/1.1 200 OK
> // __ Hdrs.length: |0|
> ~
> a similar code using a URLConnection
> ~
> Map.Entry<String, List<String>> MEntS;
>
> String aURL = "http://www.google.com/";
> URL url = new URL(aURL);
> URLConnection urlCnx = url.openConnection();
> // __
> Map<String, List<String>> MSLSHdrs = urlCnx.getHeaderFields();
> Set<Map.Entry<String, List<String>>> MapEntSet = MSLSHdrs.entrySet();
> Iterator<Map.Entry<String,List<String>>> Itr = MapEntSet.iterator();
>
> while(Itr.hasNext()){
> MEntS = Itr.next();
> System.err.println("|" + MEntS.getKey() + ":" + MEntS.getValue() + "|");
> }
> ~
> would give you:
> ~
> /*
> |null:[HTTP/1.1 200 OK]|
> |Date:[Sat, 15 Jan 2011 04:49:48 GMT]|
> |Transfer-Encoding:[chunked]|
> |Expires:[-1]|
> |X-XSS-Protection:[1; mode=block]|
> |Set-Cookie:[NID=42=Sp3E6XKMXzn9YQJsjFkaGqmmwPxrJfBw9sOT9gK5ODPE5GnUGM96wn-zRZlwZF6VYAbTsU3xKm2S2JDI1yZckDGCeP-7HxAeZxb1EqBKrycAA6q0f2NnndV8b9m-XZ-8;
> expires=Sun, 17-Jul-2011 04:49:48 GMT; path=/; domain=.google.com;
> HttpOnly,
> PREF=ID=ce8d64aa02b76584:FF=0:TM=1295066988:LM=1295066988:S=vAQP1JSCqQlyu0qq;
> expires=Mon, 14-Jan-2013 04:49:48 GMT; path=/; domain=.google.com]|
> |Content-Type:[text/html; charset=ISO-8859-1]|
> |Server:[gws]|
> |Cache-Control:[private, max-age=0]|
> */
> ~
> I need to get the response headers and after some heuristics I would
> decide to download the page or not. What would be the advantage of
> using the HttpClient library to design some sort of HTTP cache?
> ~
> Thanks
> lbrtchx
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>
Regards,
Bindul
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]