我需要向网络服务发帖子。 Web服务具有以下结构:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:kn="http://..//soapAction">
<soap:Header/>
<soap:Body>
<kn:InsertOrders>
<!--Optional:-->
<kn:XmlOrders>?</kn:XmlOrders>
<kn:stringLength>?</kn:stringLength>
<!--Optional:-->
<kn:LoadListId>?</kn:LoadListId>
</kn:InsertOrders>
</soap:Body>
</soap:Envelope>
XmlOrders接受一个字符串,我试图在其中传递以下xml字符串:
<?xml version="1.0" encoding="utf-8"?> <EXAMPLE xmlns="EXAMPLE"> <HEADER> <ID>G112233</ID> <TR>AB123</TR> </HEADER> <HEADER> <ID>G123123</ID> <TR>AB1234</TR> </HEADER> <DETAIL> <DETAILID>123123123</DETAILID> <TXT>ATR_123</TXT> </DETAIL> <DETAIL> <DETAILID>123123123</DETAILID> <TXT>ATR_123</TXT> </DETAIL> </EXAMPLE>
然而,SoapUI返回400个错误请求:
Wed May 16 12:41:19 EEST 2018:DEBUG:Receiving response: HTTP/1.1 400 Bad Request
Wed May 16 12:41:19 EEST 2018:DEBUG:Connection can be kept alive indefinitely
有人对此有任何想法吗?
答案 0 :(得分:0)
是的,您可以将XML转换为String并将其设置为Method call。
最终,当XML转换为String
时' is replaced with '
" is replaced with "
& is replaced with &
< is replaced with <
> is replaced with >
请参阅XML escaping以获取更多详细信息。
您的示例XML将变为 -
<?xml version="1.0" encoding="utf-8"?> <EXAMPLE xmlns="EXAMPLE"> <HEADER> <ID>G112233</ID> <TR>AB123</TR> </HEADER> <HEADER> <ID>G123123</ID> <TR>AB1234</TR> </HEADER> <DETAIL> <DETAILID>123123123</DETAILID> <TXT>ATR_123</TXT> </DETAIL> <DETAIL> <DETAILID>123123123</DETAILID> <TXT>ATR_123</TXT> </DETAIL> </EXAMPLE>
答案 1 :(得分:0)
我在这里发布这个答案,因为这就解决了我的问题。我把XML String包装在里面:
"<![CDATA[" + myXMLString + "]]>"
它实际上解析了XML String而没有对其进行编码,或者转义字符> , < , & , ', "
。