Il file che sto tentando di caricare sarà sempre un file xml. Voglio impostare il tipo di contenuto come application/xml Ecco il mio codice:Come impostare il tipo di contenuto per il file nel caricamento multipart quando si utilizza RestTemplate (da un client di riposo)
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'
richiesta grezzo assomiglia a questo:
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 ..
Il contenuto-tipo di file sia generato come 'application/octet-stream' dove voglio che sia 'application/xml' Come posso impostare il tipo di contenuto per il file?
Date un'occhiata a questo: http://stackoverflow.com/questions/11579621/spring -resttemplate-postforobject-with-header-webservice-cant-find-my-header-p o http://stackoverflow.com/questions/3616359/who-sets-response-content-type-in-spring-mvc-responsebody – Dan