欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

调用别人接口返回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);