spring调用第三方接口
程序员文章站
2024-01-28 12:46:34
...
post请求
- content-type:json
//呼叫客服服务
userData.put("accountid", "-1");
//设置请求头
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/json");
headers.add("Content-Type", contentType);
//userData 是请求体body
HttpEntity<Object> entity = new HttpEntity<>(userData, headers);
ResponseEntity resp = HttpUtil.restTemplate.exchange(sendMessageUrl, HttpMethod.POST, entity, Object.class);
- content-type:application/x-www-form-urlencoded
MultiValueMap<String, String> postParameters = new LinkedMultiValueMap<>();
postParameters.put("param1", Collections.singletonList(param1));
HttpHeaders headers = new HttpHeaders();
headers.add("Accept", "application/json");
headers.add("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
HttpEntity<Object> entity = new HttpEntity<>(postParameters, headers);
ResponseEntity responseEnt
上一篇: PHP中source #N问题的解决方法
下一篇: PHP Session 保险