相关疑难解决方法(0)

使用HttpGet返回完整的HTML代码

我正在尝试调用一个私有Web服务,其中有一个链接我将使用GET方法访问.在浏览器上使用直接URL(需要先登录)时,我获得了JSON格式的数据.我调用的URL是这样的

 http://www.example.com/trip/details/860720?format=json
Run Code Online (Sandbox Code Playgroud)

url工作正常,但是当我调用它时HttpGet,我得到的是网页的HTML编码,而不是JSON字符串.我使用的代码如下:

private String runURL(String src,int id) {   //src="http://www.example.com/trip/details/"
    HttpClient httpclient = new DefaultHttpClient();   
    HttpGet httpget = new HttpGet(src); 
    String responseBody="";
        BasicHttpParams params=new BasicHttpParams();
        params.setParameter("domain", token); //The access token I am getting after the Login
        params.setParameter("format", "json");
        params.setParameter("id", id);
        try {
                httpget.setParams(params);
                HttpResponse response = httpclient.execute(httpget);
                responseBody = EntityUtils.toString(response.getEntity());
                Log.d("runURL", "response " + responseBody); //prints the complete HTML code of the web-page
            } catch (Exception e) {
                e.printStackTrace();
        } 
        return responseBody;
}
Run Code Online (Sandbox Code Playgroud)

你能告诉我这里我做错了什么吗?

android web-services http-get

1
推荐指数
1
解决办法
1万
查看次数

标签 统计

android ×1

http-get ×1

web-services ×1