我正尝试向服务器发送一个http post请求作为多部分请求,但api的响应始终返回为。我已经完成了以下代码,但无法找出问题所在。多部分请求的响应正在返回
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;
}
2015-02-11
pks
+0
这似乎是一个服务器问题给我。您确定该Web服务已正确配置以返回您期望的值吗? –
2015-02-11 07:33:30
+0
是Web服务已正确配置。因为它在I-PHONE上工作正常 –
2015-02-11 07:35:02
+0
从我所看到的(我并不真正熟悉MultiPartEntity),代码没有任何问题。您要么访问错误的网址,要么网络服务出现问题。检查URL并查看您是否访问了正确的URL。 –
2015-02-11 07:39:39