views:

22

answers:

1

hi all, I'm doing a basic HEAD request using httpclient library. I'm curious how I'd be able to get the character set that apache returns E.g.: utf-8, iso-8859-1, etc... thanks!

  HttpParams httpParams = new BasicHttpParams();
  HttpConnectionParams.setConnectionTimeout(httpParams, 2000);
  HttpConnectionParams.setSoTimeout(httpParams, 2000);

  DefaultHttpClient httpclient = new DefaultHttpClient(httpParams);
  httpclient.getParams().setParameter("http.useragent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)");

  HttpContext localContext = new BasicHttpContext();
  httpget = new HttpHead(url); 

  HttpResponse response = httpclient.execute(httpget, localContext);

  this.sparrowResult.statusCode = response.getStatusLine().getStatusCode();

WORKING RESULT UPDATED

Header contentType = response.getFirstHeader("Content-Type");
String charset= contentType.getValue();
+1  A: 

in HTTP 1.1, the character set is in the Content-Type Header

HTTP/1.1 200 OK
Content-Type: text/plain; charset=utf-8

So that should be buried in

HttpResponse.Headers

So, this should work

HttpResponse.Headers.["Content-Type"]

** didnt test this, but you get the idea

Taylor
worked thanks :)