@Override
protected JSONArray doInBackground(Long... ids) {
id=ids[0];
apiURL="http://api.steampowered.com/ISteamUserStats/GetUserStatsForGame/v0002/?appid=730&key=534FA68616FC166C4A9F11CEB01B9929&steamid=76561197976528744&format=json";
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost(apiURL);
httppost.setHeader("Content-type", "application/json");
InputStream inputStream = null;
String result = null;
try {
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
inputStream = entity.getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
jObject=new JSONObject(result);
} catch (Exception e) {
}
finally {
try{if(inputStream != null)inputStream.close();}catch(Exception ex){}
}
return jsonArray;
}
在上面的代码中,我在 sb.append() 行上有一个断点。看着这一行,我可以看到我收到了 404 错误,但是如果您将 url 复制并粘贴到浏览器中,您会看到它是一个有效的地址。我在清单中使用互联网许可,所以我不确定这里发生了什么。关于为什么它的 404ing 的任何想法?