【发布时间】:2012-09-13 11:26:52
【问题描述】:
我想向服务器发送 POST 请求。我必须将 JSON 对象作为参数传递,并获取 JSON 作为响应,但我收到此错误:
org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [com.package.Response] and content type [application/octet-stream]
代码
发送请求:
@RestService
RestClient restClient;
...
String json = "{\"param\":3}";
restClient.getRestTemplate().getMessageConverters().add(new GsonHttpMessageConverter());
Response res = restClient.send(json);
RestClient
@Rest("http://my-url.com")
public interface RestClient
{
@Post("/something/")
Response send(String json);
RestTemplate getRestTemplate();
void setRestTemplate(RestTemplate restTemplate);
}
我正在使用这些 JAR 文件:
- spring-android-rest-template-1.0.0.RC1
- spring-android-core-1.0.0.RC1
- spring-android-auth-1.0.0.RC1
- gson-2.2.2
我做错了什么?
当我将 send 参数更改为 JSONObject 时,我遇到了同样的错误。
顺便提一句。 AA 文档真的很神秘——我可以使用 Gson 吗?
或者我应该使用杰克逊?
那么我需要包含哪个文件?
感谢您的帮助!
【问题讨论】:
标签: android gson resttemplate android-annotations