67,512
社区成员
发帖
与我相关
我的任务
分享
HttpClient代码:
CloseableHttpClient httpClient=HttpClients.createDefault();
CloseableHttpResponse response=null;
HttpPut put=new HttpPut("url访问");
put.setHeader("Content-type", "application/json");
Info info=new Info("1", "2017", "傻逼");
ObjectMapper mapper=new ObjectMapper();
String params=null;
try {
params = mapper.writeValueAsString(info);
StringEntity stringEntity=new StringEntity(params, "UTF-8");
put.setEntity(stringEntity);
response=httpClient.execute(put);
}
catch (Exception e) {
e.printStackTrace();
}finally{
if(httpClient!=null){
try {
httpClient.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(response!=null){
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Controller代码:
@RequestMapping("/路径")
public String testUrl(@RequestBody Info info){
System.out.println("name="+info.getName());
return null;
}