How-To: URL Encode NSString with UTF-8 Characters in Objective-C

No comments on How-To: URL Encode NSString with UTF-8 Characters in Objective-C

Written by

in

Let’s say you have to send a POST HTTP request that contains UTF-8 characters. But the problem is that url will not be formed if you simply try to generate it from a string. I managed that problem in the following way:

</p>
<pre>NSLog(@"The urlString is: >>>>>%@<<<<<", urlString);

NSString* escapedUrlString =[urlString stringByAddingPercentEscapesUsingEncoding:
NSUTF8StringEncoding];
NSLog(@"The urlString is: >>>>>%@<<<<<", escapedUrlString);

NSURL* url = [NSURL URLWithString: escapedUrlString];
NSLog(@"The url is: >>>>>%@<<<<<", url);</pre>
<p>

References:

http://blog.evandavey.com/2009/01/how-to-url-encode-nsstring-in-objective-c.html

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *