1
我使用POST方法多次在過去,但得到這個怪異的網絡服務。它在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);
感謝
請解釋更多關於這個問題,你會收到一個錯誤? logcat的?如果你調試的代碼輸入if(statusCode!= HttpStatus.SC_OK)? –
我收到回覆,但它的{「消息」:「發生了錯誤。」}。它的服務器錯誤500. – Jan
範你訪問服務器日誌或寫一些日誌來檢查這個錯誤的主要細節? –