【发布时间】:2013-07-17 08:55:22
【问题描述】:
我正在尝试解决我的RestTemplate PUT 请求的问题。基本上,服务器期望数据(一个对象)被放入“原始”内容类型,但作为 xml 流。
我尝试了许多组合(转换器、内容类型等),但没有任何帮助。我要么最终以" org.springframework.web.client.RestClientException: Could not write request: no suitable HttpMessageConverter found for request type com.test.myObject" 的身份出现异常
或者:
"The server encountered an error processing the request.
The exception message is 'Incoming message for operation 'SendRequest' contains
an unrecognized http body format value 'Xml'. The expected body format value is 'Raw'.
This can be because a WebContentTypeMapper has not been configured on the binding.
".
任何解决此问题的建议都将非常有价值。
【问题讨论】:
-
你能发布你是如何配置你的 RestTemplate 的吗?您似乎错过了设置消息转换器。
-
RestTemplate restTemplate = new RestTemplate(true); HttpHeaders 标头 = 新的 HttpHeaders(); headers.setContentType(new MediaType("application", "Xml")); HttpEntity
requestEntity = new HttpEntity (myObject, headers); ResponseEntity responseEntity = restTemplate.exchange(url, HttpMethod.PUT, requestEntity, String.class); HttpStatus 状态 = responseEntity.getStatusCode(); -
...以及您正在使用的确切内容类型?
-
服务器期望内容类型为“原始”。当我将代码修改为 headers.setContentType(new MediaType("application", "Raw"));我得到异常,org.springframework.web.client.RestClientException:无法写入请求:没有为请求类型 com.test.myObject 找到合适的 HttpMessageConverter
-
我无法控制服务器的实现。需要找出一种方法来 PUT/POST 保持内容类型为 Raw 的数据。
标签: android spring resttemplate