dongsonglian7303 2014-03-31 22:59
浏览 37
已采纳

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

I have a base64 string (for an in app iOS purchase) and trying to send it to my PHP server so it can validate with apple.

Problem is the string sent is not the string recieved. All the "+" marks inside my string are removed. How can I preserve my string just as it is in the client so my PHP server gets it raw.

Here is my client code

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];

And on my server its this

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

When I trace out the string before and after the server touches it, all the "+" symbols are missing.

Any and all advice appreciated!

UPDATE

Thanks to the kind answer below doing this fixed the issue:

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

1条回答 默认 最新

  • douchuituo3032 2014-04-03 00:46
    关注

    You should url encode the values you want to send.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)