繁体   English   中英

从发送到服务器(Objective-C到PHP服务器)的字符串中删除“ +”

[英]“+” removed from string sent to server (Objective-C to PHP server)

我有一个base64字符串(用于在iOS中购买应用程序内的iOS程序),并尝试将其发送到我的PHP服务器,以便可以与Apple进行验证。

问题是发送的字符串不是收到的字符串。 我的字符串中的所有“ +”标记都被删除。 我如何像在客户端中一样保留字符串,以便我的PHP服务器将其原始。

这是我的客户代码

NSDictionary* post = @{@"receipt":[receipt base64EncodedStringWithOptions:0]};
//combines my post with an endpoint inside _post

   for (NSString* k in _post)
       {
           NSLog(@"%@ & %@",k,_post[k]);
           postDataStr = [NSString stringWithFormat:@"%@&%@=%@", postDataStr,k,_post[k]];
       }
   _req = [NSMutableURLRequest requestWithURL:_url cachePolicy:0 timeoutInterval:15.0f];
   [_req setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
   [_req setHTTPMethod:@"POST"];
   [_req setHTTPBody:[postDataStr dataUsingEncoding:NSUTF8StringEncoding]];

   _data = [NSMutableData data];

   [NSURLConnection connectionWithRequest:_req delegate:self];

在我的服务器上

$ appleReturnedReceipt = $ this-> getReceiptData($ _ REQUEST ['receipt'],$ _REQUEST ['sandbox']);

当我在服务器触摸它之前和之后找出该字符串时,所有的“ +”符号都丢失了。

任何和所有建议表示赞赏!

UPDATE

感谢下面的友好回答,此操作解决了此问题:

NSString* newPost = [(NSString*)_post[k] stringByReplacingOccurrencesOfString:@"+" withString:@"%2B"];

您应该对要发送的值进行url编码。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM