Plik, który próbuję przesłać, będzie zawsze plikiem xml. Chcę ustawić typ zawartości jako application/xml Oto mój kod:Jak ustawić typ zawartości pliku w wielostronicowym przesyłaniu podczas korzystania z narzędzia RestTemplate (z klienta odpoczynku)
MultiValueMap<String, Object parts = new LinkedMultiValueMap<String,
Object(); parts.add("subject", "some info");
ByteArrayResource xmlFile = new ByteArrayResource(stringWithXMLcontent.getBytes("UTF-8")){
@Override
public String getFilename(){
return documentName;
}
};
parts.add("attachment", xmlFile);
//sending the request using RestTemplate template;, the request is successfull
String result = template.postForObject(getRestURI(), httpEntity,String.class);
//but the content-type of file is 'application/octet-stream'
wniosek surowy wygląda następująco:
Content-Type:
multipart/form-data;boundary=gbTw7ZJbcdbHIeCRqdX81DVTFfA-oteHHEqgmlz
User-Agent: Java/1.7.0_67 Host: some.host Connection: keep-alive
Content-Length: 202866
--gbTw7ZJbcdbHIeCRqdX81DVTFfA-oteHHEqgmlz Content-Disposition: form-data; name="subject" Content-Type: text/plain;charset=ISO-8859-1
Content-Length: 19
some info
--gbTw7ZJbcdbHIeCRqdX81DVTFfA-oteHHEqgmlz Content-Disposition: form-data; name="attachment"; filename="filename.xml" Content-Type:
application/octet-stream Content-Length: 201402
....xml file contents here ..
Zawartość typ pliku jest generowany jako "application/octet-stream", gdzie chcę, aby był "application/xml" Jak mogę ustawić typ zawartości dla pliku?
Spójrz na to: http://stackoverflow.com/questions/11579621/spring -resttemplate-postforobject-with-header-webservice-cant-find-my-header-p lub http://stackoverflow.com/questions/3616359/who-sets-response-content-type-in-spring-mvc-responsebody – Dan