Android Question Problem with Http Post and Json

RVP

Active Member
Licensed User
Longtime User
I am using a Http job and Post String to communicate with a Webservice, I just ran into an error with a user who typed an & into a description field that is included in the data being sent. The formatted SOAP envelope looks like
B4X:
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:kal="http://">
   <soap:Header/>
   <soap:Body>
      <kal:dtUploadCompanyTimeTickets>
         <kal:Json>[{
"custid":"ASSHEA",
"phase":"E06","task":"E06",
"rateid":"CNS150",
"description":"Call and GoToMeeting with Amin and Jollean to make the necessary changes to the NL & NB tax rates",
"hours":"0.25",
"transdate":"2016-07-04",
"timelink":"201607181437025",
"projectdetailid":"81"}]
</kal:Json>
         <kal:compId>KAL</kal:compId>
         <kal:userid>JSZAKAL</kal:userid>
         <kal:pw></kal:pw>
         <kal:PcBatch>######</kal:PcBatch>
      </kal:dtUploadCompanyTimeTickets>
   </soap:Body>
</soap:Envelope>

The & in the description element is causing an ERROR 400 as the post is interpreting it as indicating another parameter and is therefore breaking the service. How can I avoid this?
 

OliverA

Expert
Licensed User
Longtime User
Upvote 0

OliverA

Expert
Licensed User
Longtime User
I will try that, however I suspect it will cause an issue on the other side when I try to parse the JSON I am passing?

You'll have to reverse the process. Once more, Erel provides some code you can use, see https://www.b4x.com/android/forum/t...ake-it-normal-html-decoder.58856/#post-370577
https://www.b4x.com/android/forum/t...ake-it-normal-html-decoder.58856/#post-370577
If it gets more complicated (what about an &lt; that should be a &lt; since that was in the original text), you may need to investigate some sort of SOAP class that manages all this fun stuff (maybe this https://www.b4x.com/android/forum/threads/soap-is-easier-with-soap-class.56164/ or something more commercial)
 
Upvote 0

RVP

Active Member
Licensed User
Longtime User
You'll have to reverse the process. Once more, Erel provides some code you can use, see https://www.b4x.com/android/forum/t...ake-it-normal-html-decoder.58856/#post-370577
If it gets more complicated (what about an &lt; that should be a &lt; since that was in the original text), you may need to investigate some sort of SOAP class that manages all this fun stuff (maybe this https://www.b4x.com/android/forum/threads/soap-is-easier-with-soap-class.56164/ or something more commercial)
I looked at the module, it doesn't really deal with any of that. I might look at how .net deals with it as I have a windows program that uses the same service and it has no issue with special characters.
 
Upvote 0

RVP

Active Member
Licensed User
Longtime User
How would you escape it, do you mean just the character or the whole element. I tried a couple of things that didn't work, so what would the format be?
 
Upvote 0

RVP

Active Member
Licensed User
Longtime User
I have the xml defined as a string and then I just use replace to insert the data.
 
Upvote 0

RVP

Active Member
Licensed User
Longtime User
Well I ended up changing the string to a byte array, then to a hex string and converting it back in the webservice. That way it doesn't matter what reserved characters are in it, it always works fine.
 
Upvote 0
Top