码迷,mamicode.com
首页 > 其他好文 > 详细

post请求和接收

时间:2017-07-29 12:45:22      阅读:130      评论:0      收藏:0      [点我收藏+]

标签:tty   乱码问题   out   aaa   sign   发送   efault   from   utf-8   

请求

String url = "";
try {
JSONObject jsonParam = new JSONObject();
jsonParam.put("type", type);
String sign = Md5Util.string2MD5(jsonParam.toString());
jsonParam.put("sign", sign);
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpPost method = new HttpPost(url);
if (null != jsonParam) {
//解决中文乱码问题
StringEntity entity = new StringEntity(jsonParam.toString(), "utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
method.setEntity(entity);
}
HttpResponse result = httpClient.execute(method);
url = URLDecoder.decode(url, "UTF-8");
/**请求发送成功,并得到响应**/
System.out.println("result:"+result.getStatusLine().getStatusCode());
System.out.println("url:"+url);
if (result.getStatusLine().getStatusCode() == 200) {
System.out.println("成功");
}
} catch (IOException e) {
System.out.println("post请求提交失败:" + url);
e.printStackTrace();
}

 

 

 

接收

@RequestMapping(value = "aaa",method=RequestMethod.POST)

public String wxShopPay(@RequestBody String requestBody, HttpServletRequest request){
JSONObject jsonObject = JSONObject.fromObject(requestBody);

 String type = jsonObject.getString("type");  

}

post请求和接收

标签:tty   乱码问题   out   aaa   sign   发送   efault   from   utf-8   

原文地址:http://www.cnblogs.com/tianhao2017/p/7255428.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!