I run SAME code on my PC (windows 7 64 bit, Eclipse, Java) and on a Android Virtual Machine and I get different results.
Its a small programm that shoult print me the HttpResponse fully as String.
Results on PC:
HTTP/1.1 405 Method Not Allowed [Allow: GET, HEAD, Date: Thu, 03 Nov 2011 17:57:22 GMT, Content-Type: text/html; charset=UTF-8, Server: gws, Content-Length: 11816, X-XSS-Protection: 1; mode=block, X-Frame-Options: SAMEORIGIN]
Result on Android:
org.apache.http.message.BasicHttpResponse@44ec9da8
The code I ran on PC was:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://www.google.com");
try {
HttpResponse response = httpclient.execute(httppost);
System.out.println(response.toString());
And on Android:
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://www.google.com");
try {
HttpResponse response = httpclient.execute(httppost);
return response.toString();
Im asking becasue I wrote a App that would work on PC – works with the HttpResponse content – but on android it seems that is has NO content at all…
Could anyone please explain me this? Or tell me how to get the response content (headers) as String on android?
You don’t actually run the same code.
Android’s
BasicHttpResponsecurrently has notoString()method at all and goes on to invokejava.lang.Object.toString()giving youfully.qualified.class.name@hashcode.Your desktop version of HttpClient most likely has a toString() similar to this one from HttpClient 4.1.3:
Using
toString()for any non-debugging/logging purposes isn’t good practice — you should extract the right information using actual get methods or just return theHttpResponseitself.