Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSMutableUrlRequest eats plus signs

I create NSMutableUrlRequest for sending data to server, add all necessary fields to it and then add the string for sending like this:

[theRequest setHTTPBody:[postString dataUsingEncoding: NSUTF8StringEncoding]];

postString is a usual NSString.

The problem is, when I receive this request at the server, all the plus (+) signs disappear from the http body. So if I had "abcde+fghj" on iPhone, I get "abcde fghj" on the server".

Can this be some encoding problem from using dataUsingEncoding: NSUTF8StringEncoding? Or some NSMutableUrlRequest stripping feature? What can I do to make it stop stripping plus signs? I need to receive UTF8 strings at the server side.

like image 871
Mike Avatar asked Oct 15 '22 08:10

Mike


1 Answers

The plus (+) sign is a standard shortcut for a space, in a URL's query string portion. If you want a literal +, encode it as %2b.

like image 121
Frank Shearar Avatar answered Nov 03 '22 00:11

Frank Shearar