向AFNetworking添加自定义标题,我做错了什么?

时间:2014-02-15 04:45:31

标签: ios iphone curl paypal afnetworking

curl方法如下所示,我正在向AFNetworking添加自定义标题,如下所示。但卷曲方法正在运行,但AFNetworking没有。我做错了什么?

卷曲方法:

curl https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails \
 -H "X-PAYPAL-SECURITY-USERID: someUserId" \
 -H "X-PAYPAL-SECURITY-PASSWORD: somePassword" \
 -H "X-PAYPAL-SECURITY-SIGNATURE: someSignature" \
 -H "X-PAYPAL-APPLICATION-ID: someAPPID" \
 -H "X-PAYPAL-REQUEST-DATA-FORMAT: NV" \
 -H "X-PAYPAL-RESPONSE-DATA-FORMAT: NV" \
 -d "payKey=someAPPKEY&requestEnvelope.errorLanguage=en_US"

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:kPaypalClientId forHTTPHeaderField:@"X-PAYPAL-SECURITY-USERID"];
[manager.requestSerializer setValue:kPaypalPassword forHTTPHeaderField:@"X-PAYPAL-SECURITY-PASSWORD"];
[manager.requestSerializer setValue:kPaypalSignature forHTTPHeaderField:@"X-PAYPAL-SECURITY-SIGNATURE"];
[manager.requestSerializer setValue:appId forHTTPHeaderField:@"X-PAYPAL-APPLICATION-ID"];
[manager.requestSerializer setValue:@"NV" forHTTPHeaderField:@"X-PAYPAL-REQUEST-DATA-FORMAT"];
[manager.requestSerializer setValue:@"json" forHTTPHeaderField:@"X-PAYPAL-RESPONSE-DATA-FORMAT"];

[manager GET:@"https://svcs.sandbox.paypal.com/AdaptivePayments/PaymentDetails" parameters:@{@"payKey": payKey, @"requestEnvelope.errorLanguage": @"en_US"} success:^(AFHTTPRequestOperation *operation, id responseObject) {
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
    NSLog(@"Error: %@", error);
}];

我没有从失败阻止中获得错误。但这作为responseObject返回,但如果我使用上面的curl方法。它的回应是成功的。和标题值相同。:

{
    error =     (
                {
            category = Application;
            domain = PLATFORM;
            errorId = 520003;
            message = "Authentication failed. API credentials are incorrect.";
            severity = Error;
            subdomain = Application;
        }
    );
    responseEnvelope =     {
        ack = Failure;
        build = 9641252;
        correlationId = 8f5818a80ec65;
        timestamp = "2014-02-14T22:37:30.448-08:00";
    };
}

2 个答案:

答案 0 :(得分:0)

您正在curl中发送POST请求并在AFNetworking中发送GET请求,请使用-v检查您的卷曲请求。

答案 1 :(得分:0)

我用NSURSSession重写它,它起作用了。看来我使用AfNetWorking做得不对。