Why do I get the proper URL response from a browser, but empty within Android's “HttpGet”?

StackOverflow https://stackoverflow.com/questions/3520197

  •  29-09-2019
  •  | 
  •  

Question

I am writing an android application which uses a REST-based API on the server. So far the login works perfectly using HttpGet = I send the credentials, it sends me back a JSON response object containing session id or failure. I then moved onto using another get api (this one is passed the sessionid) and the response I get back looks like a valid one "200 - Ok" but the response body contains nothing - 0 text.

If I take the same URL and drop it into a browser, I get all the JSON text I expect displayed in the browser window. So what is the difference between a browser request/response and that of HttpGet? Any clues as to why my HttpGet might return a 'valid' nothing?

Was it helpful?

Solution 3

It turned out to be a server-side issue. They were actually sending me empty strings when the requester was not a browser. Too bad I can't delete a question. :(

OTHER TIPS

I had the same problem. Setting user agent solved my problem:

HttpParams params = new BasicHttpParams();  
...
params.setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/534.24 (KHTML, like Gecko) Chrome/11.0.696.71");

Thats my pull() I have written

mHttpGet.setURI(url.toURI());
mResponse = mHttpClient.execute(mHttpGet);
mResponse.getEntity().getContent(); // returns inputstream

How did you do yours?!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top