Satyam
Satyam

Reputation: 15894

iOS - NSURLConnection - Proper encoding of characters in request

In my iOS application, i'm posting the request to server using NSURLConnection. The following is the code that I'm using:

NSString* str = @"http://www.myserver.com/post.php?action=rating&grade=A+&name=vasu";
NSURL *url = [NSURL URLWithString:[str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

If you see the grade, its equal to "A+"
But its posting only "A" as grade to server. Even though when I'm encoding the string appropriately, why is it not able to post the request properly?
Is it something that has to be handled on server?

Upvotes: 0

Views: 678

Answers (1)

Alladinian
Alladinian

Reputation: 35626

The + sign is a reserved character for URL encoding (for 'space'). Although the escaped value for + should be %2B after stringByAddingPercentEscapesUsingEncoding, well... it isn't. What you can do though is to add a simple category into NSString to bypass this problem. You can find a relevant blog post here and some information on URL encoding here

Upvotes: 1

Related Questions