我正在尝试使用 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/