请求
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");
}