I was playing with Apache DefaultHttpClient on Android. HttpClient follows http redirect by default. But I need to disable it. I expected a simple set property on HttpClient or HttpGet. I was wrong. :(
Found two solution after a long googling.
My code:
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpget = new HttpGet("http://....");
Solution 1: set parameter
DefaultHttpClient httpClient = new DefaultHttpClient();
BasicHttpParams params = new BasicHttpParams();
HttpClientParams.setRedirecting(params, false);
httpClient.setParams(params);
HttpGet httpget = new HttpGet("http://....");
Solution 2 - define my own redirecthandler
DefaultHttpClient httpClient = new DefaultHttpClient();
httpClient.setRedirectHandler(new DefaultRedirectHandler() {
@Override
public boolean isRedirectRequested(HttpResponse response, HttpContext context) {
return false;
}
});
HttpGet httpget = new HttpGet("http://....");
sabato, novembre 20, 2010
Iscriviti a:
Commenti sul post (Atom)
Nessun commento:
Posta un commento