Reputation: 466
I need to make a post request to a web service. The web service has the following structure:
<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 accepts a string and I'm trying to pass the following xml String in it:
<?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>
However, SoapUI returns 400 bad request:
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
Does anyone have any idea about it?
Upvotes: 1
Views: 11378
Reputation: 466
I post this answer here because this is what solved my problem. I wrapped the XML String inside:
"<![CDATA[" + myXMLString + "]]>"
It actually parsed the XML String without encoding it,or escaping the characters > , < , & , ', "
.
Upvotes: 2
Reputation: 5739
Yes, you could convert XML into String and set it into Method call.
Eventually, When XML gets converted into String
' is replaced with '
" is replaced with "
& is replaced with &
< is replaced with <
> is replaced with >
refer XML escaping for more details.
Your example XML will become--
<?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>
Upvotes: 0