Die Datei, die ich hochladen möchte, wird immer eine XML-Datei sein. Ich möchte den Content-Type als application/xml gesetzt Hier ist mein Code:So legen Sie den Inhaltstyp für die Datei im mehrteiligen Upload fest, wenn RestTemplate verwendet wird (aus einem Rest-Client)
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'
die rohe Anfrage wie folgt aussieht:
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 ..
Der Inhaltstyp der Datei erzeugt wird als 'application/octet-stream' wo soll ich es sein 'application/xml' Wie kann ich den Inhaltstyp für die Datei festlegen?
einen Blick auf diese: http://stackoverflow.com/questions/11579621/spring -resttemplate-postforobject-with-header-webservice-cant-find-my-header-p oder http://stackoverflow.com/questions/3616359/who-sset-response-content-type-in-spring-mvc-responsebody – Dan