URL rewrite at Android httpGet + InputStreamReader
If I have this piece of code and url is "http://www.example.com/someFile.txt" everything works just fine. But if I put "http://www.example.com/export/something" (with help of URL rewrite/.htaccess on the server) which in desktop browser again outputs the same result in Android I get error Error w/file: End of input at character 0 of
HttpClient httpClient = new DefaultHttpClient();
HttpContext localContext = new BasicHttpContext();
String result = "";
HttpGet httpGet = new HttpGet("http://www.example.com/export/notWorking");
HttpResponse response = null;
try {
response = httpClient.execute(httpGet, localContext);
BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String line = null;
while ((line = reader.readLine()) != null){
result += line;
}
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TO开发者_Python百科DO Auto-generated catch block
e.printStackTrace();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Hot to solve this problem?
EDIT: Help with user agent
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");
doesn't help.
Solution - pretty trivial I must say - I deleted the emulator, created a new one and then everything is working just fine...so in future - test only on the device itself :)
精彩评论