How to disable a body data getting encoded in soap, retrofit request

北慕城南 提交于 2019-12-09 03:23:09

问题


I have a request data where one of the element takes xml as value. While sending the data to the server using @Body my inner xml is getting encoded(html encoded). Because of this service is failing in server side. How to disable the inner xml getting encoded.

sample:

<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/soap/envelope/">
   <soap12:Body>
      <UpdateASN xmlns="http://tempuri.org/">
         <SecureCode>VkdWelkyOUJVMDQ9</SecureCode>
         <strXML>&lt;![CDATA[&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;NewDataSet&gt;&lt;Table&gt;&lt;ASNId&gt;21131248&lt;/ASNId&gt;&lt;ASNLineId&gt;108069195&lt;/ASNLineId&gt;&lt;EANOCC&gt;5051622303470&lt;/EANOCC&gt;&lt;TUQuantityRecevied&gt;2&lt;/TUQuantityRecevied&gt;&lt;ItemDescription&gt;sample 6X300ML&lt;/ItemDescription&gt;&lt;TUSize&gt;6&lt;/TUSize&gt;&lt;TUDespatched&gt;1&lt;/TUDespatched&gt;&lt;/Table&gt;&lt;/NewDataSet&gt;]]&gt;</strXML>
      </UpdateASN>
   </soap12:Body>
</soap12:Envelope>

回答1:


I have found it by myself.

Here is what I'm doing, I have removed enclosing the inner xml inside CDATA so that in server side it can take and decode the inner xml before processing.

If we enclose the inner xml with CDATA it won't decode the string and it make service to fail.

Here is my final request:

<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/soap/envelope/">
   <soap12:Body>
      <UpdateASN xmlns="http://tempuri.org/">
         <SecureCode>VkdWelkyOUJVMDQ9</SecureCode>
         <strXML>&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;&lt;NewDataSet&gt;&lt;Table&gt;&lt;ASNId&gt;21131248&lt;/ASNId&gt;&lt;ASNLineId&gt;108069195&lt;/ASNLineId&gt;&lt;EANOCC&gt;5051622303470&lt;/EANOCC&gt;&lt;TUQuantityRecevied&gt;2&lt;/TUQuantityRecevied&gt;&lt;ItemDescription&gt;sample 6X300ML&lt;/ItemDescription&gt;&lt;TUSize&gt;6&lt;/TUSize&gt;&lt;TUDespatched&gt;1&lt;/TUDespatched&gt;&lt;/Table&gt;&lt;/NewDataSet&gt;</strXML>
      </UpdateASN>
   </soap12:Body>
</soap12:Envelope>


来源:https://stackoverflow.com/questions/41378269/how-to-disable-a-body-data-getting-encoded-in-soap-retrofit-request

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