Android httpGet + InputStreamReader上的URL重写

时间:2011-06-22 21:23:13

标签: android url-rewriting inputstream http-get

如果我有这段代码并且网址是“http://www.example.com/someFile.txt”,一切正常。但是如果我把“http://www.example.com/export/something”(在服务器上的URL重写/ .htaccess的帮助下)在桌面浏览器中再次输出相同的结果在Android中我收到错误错误w / file:

的字符0输入结束
    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) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

热点解决这个问题?

编辑:帮助用户代理

    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");

无效。

1 个答案:

答案 0 :(得分:0)

解决方案 - 非常琐碎我必须说 - 我删除了模拟器,创建了一个新模拟器然后一切正常工作......所以将来 - 只测试设备< / strong>本身:)