我想调用一个私人的网络服务,其中有一个链接,我有访问使用GET方法。在浏览器上使用直接URL(需要先登录)时,我会以JSON格式获取数据。我调用的URL是这样的使用HttpGet返回完整的HTML代码
http://www.example.com/trip/details/860720?format=json
URL是工作正常,但是当我调用此使用HttpGet,我得到的,而不是JSON字符串的网页的HTML代码。我使用的代码如下:
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;
}
你能告诉我我在做什么错吗?
2012-03-21
noob
+0
,如果你尝试用浏览器访问的网址或卷曲 –
2012-03-21 13:15:33
+0
这是一个JSON字符串,如果我尝试通过浏览器来调用它,这是它应该是什么在Android上也有什么内容。 –
2012-03-21 13:23:34