问题
I've tested a POST request via REST API tool and getting the response in an XML format.
I'm not sure which method need to use and what should the response type class for the above.
Could someone help me with the code snippet for the same?
Thanks, Kathir
回答1:
You need to add xml message converter to covert the xml messages to java objects.
See solution Stack Overflow
Also you can capture the result in String format and manually handle it then. Example :
String xmlData = restTemplate.postForObject(url, parameters, String.class);
// pass this string to xml parser and prepare java object
Sample xml Parsing example
Hope this helps
来源:https://stackoverflow.com/questions/12184731/spring-resttemplate-post-method-for-xml-response