【发布时间】:2014-01-22 16:46:01
【问题描述】:
我过去曾多次使用 POST 方法,但得到了这个奇怪的 Web 服务。它在 chrome 扩展上运行良好,但我无法使用 android 获得此响应。如果缺少,请在代码中添加任何内容
这是我正在使用的代码
HttpParams param = new BasicHttpParams();
param.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
HttpClient httpclient = new DefaultHttpClient(param);
HttpPost httppost = new HttpPost(url);
Utils.showLogs(MyConstants.TAG, "ApplicationURL: " + url);
httppost.setHeader("Content-type", contentType);
HttpConnectionParams.setConnectionTimeout(param, MyConstants.WEBSERVICE_TIMEOUT);
HttpConnectionParams.setSoTimeout(param, MyConstants.WEBSERVICE_TIMEOUT);
String response = null;
try {
if (jsonObject == null) {
StringEntity entity = new StringEntity(json, HTTP.UTF_8);
httppost.setEntity(entity);
} else {
StringEntity stringEntity = new StringEntity(jsonObject.toString());
httppost.setEntity(stringEntity);
}
// Execute HTTP Post Request
HttpResponse httpResponse = httpclient.execute(httppost);
final int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode != HttpStatus.SC_OK) {
return MyConstants.SERVER_NOT_RESPONDING;
}
HttpEntity httpEntity = httpResponse.getEntity();
response = EntityUtils.toString(httpEntity);
谢谢
【问题讨论】:
-
请详细说明问题,您收到错误消息?日志猫?如果调试代码输入 if (statusCode != HttpStatus.SC_OK)?
-
我得到了响应,但它的 {"Message":"An error has occurred."} 。它的服务器错误 500。
-
你访问服务器日志或写一些日志来检查这个错误的主要细节?