I want to pass my textview content to a server via post request but I guess I have a problem with encoding. Do | have to convert say blanks to + or %20 by hand or is there a library supported by cocoa or any other 3rd party? Is this sth trivial ? I got stuck with this simple step for hours! :)
+3
A:
Have a look at example how to add percent escapes at http://www.rudis.net/content/2009/01/26/adding-percent-esacpes-cocoa, quoting the author:
One obvious way to do this is by calling NSString's
-(NSString*)stringByAddingPercentEscapesUsingEncoding:(NSStringEncoding)encoding
method. While this does a good job, it is not perfect and will miss things like "/", which may make some web services cry. The best way to do this encoding is to use:
CFStringRef CFURLCreateStringByAddingPercentEscapes (
CFAllocatorRef allocator,
CFStringRef originalString,
CFStringRef charactersToLeaveUnescaped,
CFStringRef legalURLCharactersToBeEscaped,
CFStringEncoding encoding
);
Example code after jump (see link above).
stefanB
2009-06-15 00:14:22
+1
A:
Another example can be found at http://deusty.blogspot.com/2006/11/sending-http-get-and-post-from-cocoa.html. The example that stefanB linked to has a more complete list of characters that need escaping, though.
hjon
2009-06-15 00:18:36
yeap, this link contains a neat and simple explanation, thanks
dkberktas
2009-06-15 23:25:14
No problem. Be sure to look at stefanB's link for a more complete list of characters to include when escaping.
hjon
2009-06-16 05:19:15