我想調用一個私人的網絡服務,其中有一個鏈接,我有訪問使用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;
}
你能告訴我我在做什麼錯嗎?
,如果你嘗試用瀏覽器訪問的網址或捲曲 – Blackbelt 2012-03-21 13:15:33
這是一個JSON字符串,如果我嘗試通過瀏覽器來調用它,這是它應該是什麼在Android上也有什麼內容。 – noob 2012-03-21 13:23:34