我正在尝试调用一个私有Web服务,其中必须使用GET方法访问一个链接.在浏览器上使用直接URL时(需要先登录),我以JSON格式获取数据.我要调用的网址是这样的
http://www.example.com/trip/details/860720?format=json
该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;
}
你能告诉我我在做什么错吗?