NSMutableUrlRequest吃加号

问题描述:

我创建了NSMutableUrlRequest来将数据发送到服务器,将所有必需的字段添加到其中,然后添加用于发送的字符串,如下所示:

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是通常的NSString.

postString is a usual NSString.

问题是,当我在服务器上收到此请求时,所有加号(+)从http正文中消失.因此,如果我在iPhone上安装了"abcde + fghj",则在服务器上会收到"abcde fghj"".

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".

使用dataUsingEncoding:NSUTF8StringEncoding会不会是一些编码问题?还是某些NSMutableUrlRequest剥离功能?我该怎么做才能使其停止剥离加号?我需要在服务器端接收UTF8字符串.

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.

加号(+)是标准快捷方式.如果要使用文字+,请将其编码为%2b.

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.