1

私はRoboSpiceの初心者です。ファイルをアップロードしようとしています。しかし、私はこのエラーが発生しました:

 04-02 17:47:31.151: E//RequestProcessor.java:234(11021): org.springframework.web.client.RestClientException: Could not extract response: no suitable HttpMessageConverter found for response type [java.lang.String] and content type [text/html]

.これは私のリクエストクラスです:

public class UploadFileRequest extends SpringAndroidSpiceRequest<String>{
private static final String TAG = "UploadFileRequest";
private UploadRequestModel requestModel;
private String link;

public UploadFileRequest(UploadRequestModel model, String link) {
    super(String.class);
    requestModel = model;
    this.link = link;
}

@Override
public String loadDataFromNetwork() throws Exception {    


    MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
    parts.add("file1", new FileSystemResource(requestModel.getFile1()));
    parts.add("file2", new FileSystemResource(requestModel.getFile1()));
    return getRestTemplate().postForObject(link, parts, String.class);


}

}

私は次の作業を行っています: JacksonSpringAndroidSpiceService クラス。

助けてくれてありがとう。

4

2 に答える 2

3

JacksonSpringAndroidSpiceService ソース コードからわかるように、クラスapplication/jsonを介して content-type のみのコンバーターを提供します。MappingJacksonHttpMessageConverter

他のコンテンツ タイプの場合、Spring はそれを処理する方法を知りません。

StringHttpMessageConverterクラスをサブクラス化JacksonSpringAndroidSpiceServiceするか、ソースコードに基づいて独自の実装ベースを作成することで、一般的な目的のコンバーターを簡単に追加できます。

于 2013-04-02T13:37:27.170 に答える
2

同様の問題があり、次の方法で解決しました

交換

return getRestTemplate().postForObject(link, parts, String.class);

RestTemplate restTemplate = getRestTemplate();
restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
return restTemplate.postForObject(link, parts, String.class);

お役に立てれば!

于 2013-04-29T00:12:16.283 に答える