@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错误,但是如果您在浏览器中复制并粘贴该网址,则会看到它是一个有效的地址。我在我的清单中使用了互联网权限,所以我不确定这里发生了什么。关于为什么要404ing的任何想法?
答案 0 :(得分:1)
将该网址复制到浏览器中会GET
。你要去POST
。
使用curl
进行检查,如果您发送到该网址,确实会返回404
:
<html>
<head>
<title>404 Not Found</title>
</head>
<body>
<h1>Not Found</h1>
</body>
</html>