POST请求中的&符号造成严重破坏

Ric*_*ich 3 iphone post ios

我有一个来自我的iPhone应用程序的简单POST.它的工作正常,除了通过一个&符号导致后端中断 - 这几乎就像它将它视为GET请求(&符号分隔变量名称).我需要先进行某种编码吗?这是代码:

NSString *content = [[NSString alloc] initWithFormat:@"data=%@&email=%@", str, emailAddress.text];

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.myurl.com/myscript.php"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:[content dataUsingEncoding:NSISOLatin1StringEncoding]];

// generates an autoreleased NSURLConnection
[NSURLConnection connectionWithRequest:request delegate:self];
Run Code Online (Sandbox Code Playgroud)

Tia*_*ida 7

我在iOS7中遇到了这个问题,并且接受的答案根本不起作用(实际上,这是我将数据发送到后端时的标准).&符号在后端打破了,所以我不得不更换&%26.后端是在python中完成的,代码是遗留的,并且正在使用ASI.

基本上我做了以下事情:

NSString *dataContent =  [NSString stringWithFormat:@"text=%@", 
    [json stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

dataContent = [dataContent stringByReplacingOccurrencesOfString:@"&" 
                                                     withString:@"%26"];
Run Code Online (Sandbox Code Playgroud)