Qiao_Y
2016-06-12 03:29httpclient的post调用sptingmvc服务,传递json到后台
httpclient的post调用springmvc服务,传递json到后台,在后台怎么接受这个json串,是想只接受这个json字符串,不是json对象
这是调用过程:
String response = null;
String params = "{\"userInfo\":\"18575584371\"}";
int timeoutConnection = 3000;
int timeoutSocket = 5000;
HttpParams httpParameters = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);
HttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpPost httpPost = new HttpPost(targetURL);
System.out.println(params);
StringEntity entity = new StringEntity(params,"utf-8");//解决中文乱码问题
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);
HttpResponse httpResponse;
httpResponse = httpClient.execute(httpPost);
int statusCode = httpResponse.getStatusLine().getStatusCode();
if (statusCode == HttpStatus.SC_OK) {
// 获得返回结果
response = EntityUtils.toString(httpResponse.getEntity());
} else {
response = "返回码:" + statusCode;
}
System.out.println(response);
后台接收:
@RequestMapping(value = "/user/login", method = RequestMethod.POST)
public Model login(Model model, @RequestParam String userInfo, HttpServletRequest request) {……}
怎么都接收不到,400错误,求大神帮忙看看
- 点赞
- 回答
- 收藏
- 复制链接分享
3条回答
为你推荐
- 测试HTTP请求时出现Nil解除引用错误
- it技术
- 互联网问答
- IT行业问题
- 计算机技术
- 编程语言问答
- 1个回答
- MultipartEntity实体代码不调用php代码/不工作
- image
- android
- entity
- php
- 1个回答
- 从HTTP post asynctask调用的SELECT语句仅在galaxy s4设备上失败
- select
- galaxy
- android
- php
- 1个回答
- 403使用Buzz客户端w / https调用api.weather.gov
- curl
- php
- 1个回答
- JAVA后端调用http Post请求,url后面拼接参数报错
- java
- 4个回答
换一换