gpt4 book ai didi

java api REST 客户端出现 POST 错误 : no suitable HttpMessageConverter

转载 作者:行者123 更新时间:2023-12-02 02:37:33 25 4
gpt4 key购买 nike

我使用 Maven + Spring,我想使用 RestTemplate().postForEntity(url, request, responseType) + Content-Type=application/json但我有这个错误:

org.springframework.web.client.RestClientException:无法写入请求:找不到适合请求类型 [com.kizeoforms.model.User] 和内容类型 [application/json] 的合适 HttpMessageConverter

java REST 客户端代码:

User user = new User();
user.setUser("foo");
user.setPassword("**********");
user.setCompany("xxxxxx");

MultiValueMap<String, String> headers = new LinkedMultiValueMap<String, String>();
headers.add("Content-Type", "application/json");
HttpEntity<User> request = new HttpEntity<User>(user, headers);
ResponseEntity<Object> response = new RestTemplate().postForEntity("https://www.kizeoforms.com:443/rest/v3/login", request, Object.class);
System.out.println(response.getStatusCode());

最佳答案

我有 new MappingJackson2HttpMessageConverter()restTemplate:

RestTemplate restTemplate = new RestTemplate();
restTemplate.getMessageConverters().add(new MappingJackson2HttpMessageConverter());
ResponseEntity<Object> response = restTemplate.postForEntity("https://www.kizeoforms.com:443/rest/v3/login", request, Object.class);

关于java api REST 客户端出现 POST 错误 : no suitable HttpMessageConverter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46059397/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com