我需要进行以下SOAP POST请求:
POST /sample/demo.asmx HTTP/1.1
Host: www.website.org
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://www.website.org/Method"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Method xmlns="https://www.ourvmc.org/">
<item1>string</item1>
<item2>string</item2>
<item3>string</item3>
<item4>string</item4>
</Method>
</soap:Body>
</soap:Envelope>
我已经达到了
POST /sample/demo.asmx HTTP/1.1
Host: www.website.org
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "https://www.website.org/Method"
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Body>
<Method xmlns="http://tempuri.org/"/>
</soap:Body>
</soap:Envelope>
我有一个名为Method的POJO类,其中包含item1、item2、item3、item4的getter和setter方法。 我需要将该POJO转换为XML格式,即
<item1>string</item1>
<item2>string</item2>
<item3>string</item3>
<item4>string</item4>
然后进行POST请求。有人能提供如何实现吗?我已经做了研究,但没有找到有用的解决方案。
StringWriter
替代文件。 - user2004685