ios - curl 到 AFNetworking?

标签 ios curl paypal afnetworking

我正在尝试使用 native iOS 应用程序中的 paypal Express 结帐(不能使用 paypal SDK,因为 apple 需要我通过 safari 进行付款)。问题是当我尝试调用 SetExpressCheckout API 方法时。这是他们在网站上提供的 curl 声明:

curl -s --insecure https://api-3t.sandbox.paypal.com/nvp -d 
"USER=callerID                        # User ID of the PayPal caller account 
&PWD=callerPswd                        # Password of the caller account 
&SIGNATURE=callerSig                   # Signature of the caller account 
&METHOD=SetExpressCheckout 
&VERSION=93 
&PAYMENTREQUEST_0_PAYMENTACTION=SALE     # type of payment 
&PAYMENTREQUEST_0_AMT=19.95              # amount of transaction 
&PAYMENTREQUEST_0_CURRENCYCODE=USD       # currency of transaction 
&RETURNURL=http://www.example.com/success.html  # URL of your payment confirmation page 
&CANCELURL=http://www.example.com/cancel.html"  # URL redirect if customer cancels payment

我需要将它传递给 AFNetworking,这样我就可以在应用程序中完成它,我已经尝试过了,但它不起作用:

NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys: kPaypalClientId,@"USER",
     kPaypalPassword, @"PWD",
      kPaypalSignature, @"SIGNATURE",
      @"SetExpressCheckout", @"METHOD",
      @"93", @"VERSION",
       @"SALE",@"PAYMENTREQUEST_0_PAYMENTACTION",
       @"19.95",@"PAYMENTREQUEST_0_AMT",
      @"USD", @"PAYMENTREQUEST_0_CURRENCYCODE",
      @"shareapp://bien",@"RETURNURL",
      @"shareapp://cancel", @"CANCELURL", nil];

    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager.requestSerializer setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
    [manager POST:@"https://api-3t.sandbox.paypal.com/nvp" parameters:params
          success:^(AFHTTPRequestOperation *operation, id responseObject) {
              NSLog(@"%@", responseObject);
              [[UIApplication sharedApplication] openURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://www.sandbox.paypal.com/cgi-bin/webscr?cmd=_express-checkout&token=%@",tokenValue]]];
          } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
              NSLog(@"Error: %@", error);
          }];

这是我遇到的错误:

Error Domain=AFNetworkingErrorDomain Code=-1016 "Request failed: unacceptable content-type: text/plain" UserInfo=0xba7de40 {NSErrorFailingURLKey=https://api-3t.sandbox.paypal.com/nvp, AFNetworkingOperationFailingURLResponseErrorKey=<NSHTTPURLResponse: 0xd06e720> { URL: https://api-3t.sandbox.paypal.com/nvp } { status code: 200, headers {
    Connection = "keep-alive";
    "Content-Length" = 230;
    "Content-Type" = "text/plain; charset=utf-8";
    DC = "origin1-api-3t.sandbox.paypal.com";
    Date = "Tue, 15 Apr 2014 13:36:59 GMT";
    Server = Apache;
    "Set-Cookie" = "DC=origin1-api-3t.sandbox.paypal.com; secure";
} }, NSLocalizedDescription=Request failed: unacceptable content-type: text/plain}

谢谢你,对不起我的英语!!

最佳答案

这一行为我解决了这个问题:

manager.responseSerializer = [AFHTTPResponseSerializer serializer];

关于ios - curl 到 AFNetworking?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23085405/

相关文章:

ios - 嵌入 pods 框架 - Command/bin/sh 失败,退出代码为 1

iphone - Modal ViewController 在没有动画的情况下弹出,错误?

ios - 试图模仿 Mail.app 撰写动画,使图层保持在 View 中

objective-c - Swift(或 objective-c)相当于 curl 请求

curl - Youtube Data API 中的 "Your Access Token"是什么以及如何获取它?

php - Paypal PHP SDK Credications and Authentication,我无法让它工作

html - 网站支付标准 : How would I connect the order being sent and the IPN receiving it?

ios - 下推所有 View 并添加自定义 View

php - 在外部网站上完成预订后检索信息(cURL、iFrame...?)

android - Paypal Android SDK 2.3.1 集成错误 APP 挂起