Spring RestTemplate POST method for Xml Response?

吃可爱长大的小学妹 提交于 2019-12-07 12:03:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!