-1
我有以下代码为“POST”请求,其中,我有一个API和参数。 但是,在这里我没有得到任何回应,也没有错误。 PLZ帮助我。没有得到JSON响应
public JSONObject makeHttpRequest(String url, List<NameValuePair> params) throws Exception {
// Making HTTP request
try {
Log.d("URL :", url);
Log.d("params :", params.toString());
// defaultHttpClient
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params));
HttpResponse httpResponse = httpClient.execute(httpPost);
HttpEntity httpEntity = httpResponse.getEntity();
is = httpEntity.getContent();
Log.d("InputStreem :", is.toString());
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
Log.d("BufferedReader :", reader.toString());
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
jsonResponse = sb.toString();
System.out.println("Respose :"+jsonResponse);//Here Resonse: "nothing"
} catch (Exception e) {
throw new Exception(e.getMessage());
}
// try parse the string to a JSON object
try {
jsonData = new JSONObject(jsonResponse);
} catch (JSONException e) {
throw new Exception(e.getMessage());
}
// return JSON String
return jsonData;
}
你必须在另一个'thread'中运行你的代码。你的'httpResponse'是什么? – SerCna 2014-09-11 07:31:16
您是否尝试过使用PC浏览器中的REST客户端进行POST?这会返回什么吗? – 0101100101 2014-09-11 07:32:01
当我打印jsonResponse时,它什么也没有显示。 – 2014-09-11 07:35:51