尝试使用以下代码在我的客户端(Android应用程序)端运行httppost
时,但在我的浏览器上,我确实只收到预期数据的JSON输出。
protected String doInBackground(String... params) {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://192.168.43.229/thecee/mobile_app/the_lost.php");
// Depends on your web service
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();
// json is UTF-8 by default
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();
Log.d("The Content", result);
} catch (Exception e) {
// Oops
}
finally{
try {
if (inputStream != null) inputStream.close();
} catch (Exception squish) {
}
}
return result;
}
我在尝试解析时收到以下错误消息。
03-31 04:29:50.463 18871-19413 / com.example.ji.thecce D / The Content: http://www.w3.org/1999/xhtml'> 请求失败
响应错误。
技术说明:
03-31 04:29:50.466 18871-18871 / com.example.ji.thecce W / System.err:org.json.JSONException:Value
502 Bad Gateway - 响应错误,a 从另一个代理服务器或目的地收到错误的响应 原始服务器。
我将真诚地感谢您的回复。 谢谢你的时间。