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.

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

报告相同问题?

悬赏问题

  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 unity第一人称射击小游戏,有demo,在原脚本的基础上进行修改以达到要求
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line