I am sending a post containing text, numbers and data. The numbers and data work fine, but I’m having problems with the text, since it may contain an ampersand (&). For example
page.php?text=Hello World & Space.
Now I found that the “&” is received by server, but read as if a new variable starts. So it sees (I think):
text = "Hello World "
Space. =
I did read that I could try to encode the text to make it look like it’s a URL (like ” ” [space] turns into “%20”) but there is no way to encode it properly. I came to the conclusion:
textToPOST = [text stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding];
But that does NOT encode the ampersands, but everything else. So the result is:
some text ü blablabla
turns into
some%20text%20ü%20blablabla
with the & not encoded. So how can I do this, please help.
Thanks a lot already
Thanks for that answer and sorry for my premature posting :S I hope it at least helps anybody who has the same issue as I had. I just had a chat with a friend and he told me:
So that’s how you solve the “How do I parse XML with an amp in it problem“. Also I managed to make the code, from the website I linked in a comment to my original question, work:
This works fine for me and does replace ampersands and any other possible hazards.
If you don’t want many %20 escapes for every space, you can also use:
Thank you all 🙂