PDA

View Full Version : Does stringbyadding percentescapes usingencoding work?




fenrus110
Nov 27, 2008, 02:50 PM
I searched a few threads about it and people said it worked. I tried both NSASCIIStringEncoding and NSUTF8StringEncoding. I NSLogged it and it appears to escape spaces with %20, but it doesn't escape any other characters.

and for the record, I have always passed stuff like the @ and < symbols fine without escape. But the main problem is with the & character, because that is a symbol for a POST parameter.

And that above method doesn't escape it, only the spaces.



dejo
Nov 27, 2008, 08:41 PM
stringByAddingPercentEscapesUsingEncoding:
Returns a representation of the receiver using a given encoding to determine the percent escapes necessary to convert the receiver into a legal URL string.

In a legal URL string, &'s don't need to be encoded. What are you trying to do with this string once you have it encoded?

fenrus110
Nov 28, 2008, 11:32 AM
well I'm just trying to post stuff from a UITextView onto a server. Works fine and dandy, except when I run into characters like & and <

Haven't totally ironed out the details, but I do know that getting back the data is a problem, because when I need to get the data back, it's in XML format.

I guess I could manually do a character replace with the string replace functions.

dejo
Nov 28, 2008, 11:39 AM
well I'm just trying to post stuff from a UITextView onto a server. Works fine and dandy, except when I run into characters like & and <

Haven't totally ironed out the details, but I do know that getting back the data is a problem, because when I need to get the data back, it's in XML format.
You probably want to start looking into NSXMLParser then.

I guess I could manually do a character replace with the string replace functions.
Also look into maybe using CFURLCreateStringByAddingPercentEscapes.