Android 关于Josn实现httppost 获取数据

biao_qi 2016-03-16 03:15:24

[SoapHeader("soapHeader")]
[WebMethod(Description = "测试参数为List<string> ")]
public string Test(List<string> iDList)
{
log.Info(iDList);
return ReturnFormatJson.WriteSuccess("", iDList);
}



public void Test() {
try {
List<String> iDList =new ArrayList<String>();
iDList.add("0000001");
iDList.add("0000002");
iDList.add("0000003");
JSONObject pParameters = new JSONObject();
pParameters.put("iDList", iDList);
HttpResponse response = post("Test", pParameters);
int code = response.getStatusLine().getStatusCode();
if (code == 200) {
String strEntity = EntityUtils.toString(response.getEntity());
} else {
response.getEntity().getContent().close();
}
} catch (Exception e) {
e.printStackTrace();
}
}

protected HttpResponse post(String pMethodName, JSONObject pParameters) {

HttpResponse response = null;
String baseURL = Configure.WEBSERVICEURL + pMethodName;
try {
HttpParams httpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, TIMEOUT_MILLISEC);
HttpConnectionParams.setSoTimeout(httpParams, TIMEOUT_MILLISEC);
HttpClient httpclient = new DefaultHttpClient(httpParams);

HttpPost httppost = new HttpPost(baseURL);

// 添加http Header 信息
// httppost.setHeader("Range","bytes="+"");
httppost.setHeader("Accept", "application/json");
httppost.addHeader("Content-Type", "application/json; charset=utf-8");
httppost.addHeader("CallName", "Vashion");
httppost.addHeader("CallPassword", "Vashion@Pass2016");

// 添加 json 参数
if (pParameters != null) {
httppost.setEntity(new StringEntity(pParameters.toString(), HTTP.UTF_8));
}
// execute
response = httpclient.execute(httppost );
} catch (IOException e) {
e.printStackTrace();
}

return response;
}



结果是
HTTP/1.1 500 Internal Server Error

这样的webservice 参数应该怎么传递

如果参数是自定义的Class 更复杂的情况

应该怎么处理

...全文
335 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

80,350

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧