调用别人接口返回406
程序员文章站
2022-03-09 19:11:56
...
接受别人的接口的参数类型有错误,可以试试 String.
HttpHeaders headers = new HttpHeaders();
headers.set("token", "XXXX");
MultiValueMap<String, Object> multiValueMap = new LinkedMultiValueMap<>();
//参数列表
multiValueMap.add("xxx", xxx);
HttpEntity<MultiValueMap<String, Object>> requestEntity = new HttpEntity<>(multiValueMap, headers);
//url = ip
ResponseEntity<String> response = RestTemplateUtils.getRestTemplate().exchange(url, HttpMethod.POST, requestEntity, String.class);
//import org.apache.commons.lang.StringEscapeUtils;
String s = StringEscapeUtils.unescapeJavaScript(response.getBody());
MyObjectbody = gson.fromJson(s, MyObject.class);
上一篇: vs code编辑器
下一篇: 2.工厂方法模式