0
我正嘗試向服務器發送一個http post請求作爲多部分請求,但api的響應始終返回爲。我已經完成了以下代碼,但無法找出問題所在。多部分請求的響應正在返回<!DOCTYPE html>
String saveGroupUrl = getResources().getString(R.string.base_url)+ getResources().getString(R.string.save_group);
Log.v("save group url==>", saveGroupUrl);
HttpPost httppost = new HttpPost(saveGroupUrl);
HttpContext localContext = new BasicHttpContext();
MultipartEntity entity = new MultipartEntity(
HttpMultipartMode.BROWSER_COMPATIBLE);
HttpClient httpClient = new DefaultHttpClient();
try {
entity.addPart("device_id",new StringBody(My_Application.androidId));
entity.addPart("token_no",new StringBody(prefs.gettokendata()));
entity.addPart("user_id",new StringBody(prefs.getuserid()));
entity.addPart("group_name", new StringBody(strGrpName));
Log.v("group name==>", strGrpName);
entity.addPart("short_desc", new StringBody(strDesc));
Log.v("group desc==>", strDesc);
entity.addPart("description", new StringBody(strLongDesc));
Log.v("group long desc==>", strLongDesc);
httppost.setEntity(entity);
HttpResponse response = httpClient.execute(httppost);
HttpEntity resEntity = response.getEntity();
if (resEntity != null) {
Log.i("RESPONSE",EntityUtils.toString(resEntity));
}
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
這似乎是一個服務器問題給我。您確定該Web服務已正確配置以返回您期望的值嗎? – 2015-02-11 07:33:30
是Web服務已正確配置。因爲它在I-PHONE上工作正常 – pks 2015-02-11 07:35:02
從我所看到的(我並不真正熟悉MultiPartEntity),代碼沒有任何問題。您要麼訪問錯誤的網址,要麼網絡服務出現問題。檢查URL並查看您是否訪問了正確的URL。 – 2015-02-11 07:39:39