用于 Xml 响应的 Spring RestTemplate POST 方法? [英] Spring RestTemplate POST method for Xml Response?

查看:104
本文介绍了用于 Xml 响应的 Spring RestTemplate POST 方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经通过 REST API 工具测试了 POST 请求并以 XML 格式获取响应.

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?

谢谢,凯瑟尔

推荐答案

需要添加xml消息转换器,将xml消息转换为java对象.

You need to add xml message converter to covert the xml messages to java objects.

查看解决方案 堆栈溢出

您也可以以字符串格式捕获结果,然后手动处理.示例:

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

示例 xml 解析示例

希望能帮到你

这篇关于用于 Xml 响应的 Spring RestTemplate POST 方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆