0
今私は、APISを使用してpaypalの定期的な統合に取り組んでいます。私は次のAPIのリクエストフォーマットの問題に直面しています。 仲間と同じリクエスト形式を送信する方法。AFNetworkingを使用して配列値を渡す方法は?
curl -v -k -X PATCH 'https://api.sandbox.paypal.com/v1/payments/billing-plans/P-94458432VR012762KRWBZEUA' \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <Access-Token>" \
-d '[
{
"path": "/",
"value": {
"state": "ACTIVE"
},
"op": "replace"
}
]'
これまでのところ、私はコード
NSDictionary *valueDic = @{@"state":@"ACTIVE"};
NSDictionary *parametersDic = @{@"path":@"/",@"value":valueDic,@"op":@"replace"};
NSMutableArray *parameterArray = [[NSMutableArray alloc] init];
[parameterArray addObject:parametersDic];
NSString *finalyToken = [[NSString alloc]initWithFormat:@"Bearer %@",strAccessToken];
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
manager.requestSerializer = [AFJSONRequestSerializer serializer];
manager.responseSerializer = [AFJSONResponseSerializer serializer];
[manager.requestSerializer setValue:finalyToken forHTTPHeaderField:@"Authorization"];
[manager.requestSerializer setValue:@"application/json+patch" forHTTPHeaderField:@"Content-Type"];
[manager.responseSerializer.acceptableContentTypes setByAddingObject:@"application/json"];
NSString *urlPatch = [NSString stringWithFormat:@"https://api.sandbox.paypal.com/v1/payments/billing-plans/%@",creditCardId];
[manager PATCH:urlPatch parameters:parameterArray success:^(AFHTTPRequestOperation *operation, id responseObject){
NSLog(@"JSON: %@", responseObject);
[self recurringCreateBillingAgreement];
}failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
次試してみましたあなたは、私が
上記(
{
op = replace;
path = "/";
value = {
state = ACTIVE;
};
}
)
よう要求フォーマットを作成している。しかし、私は次のようなエラーに
Error: Error Domain=com.alamofire.error.serialization.response Code=-1011 "Request failed: internal server error (500)" UserInfo=0x177155d0 {com.alamofire.serialization.response.error.response=<NSHTTPURLResponse: 0x1755c9b0> { URL: https://api.sandbox.paypal.com/v1/payments/billing-plans/P-1DT55351E261652436BZHSLA } { status code: 500, headers {
"CORRELATION-ID" = 6bf7cbf78bb16;
Connection = "close, close";
"Content-Length" = 196;
"Content-Type" = "text/xml;charset=UTF-8";
Date = "Thu, 07 Apr 2016 11:19:08 GMT";
"PROXY_SERVER_INFO" = "host=slcsbplatformapiserv3001.slc.paypal.com;threadId=368";
"Paypal-Debug-Id" = "6bf7cbf78bb16, 6bf7cbf78bb16";
Server = Apache;
"Set-Cookie" = "X-PP-SILOVER=name%3DSANDBOX3.API.1%26silo_version%3D1880%26app%3Dplatformapiserv%26TIME%3D742524503; domain=.paypal.com; path=/; Secure; HttpOnly, X-PP-SILOVER=; Expires=Thu, 01 Jan 1970 00:00:01 GMT";
Vary = Authorization;
} }, NSErrorFailingURLKey=https://api.sandbox.paypal.com/v1/payments/billing-plans/P-1DT55351E261652436BZHSLA, NSLocalizedDescription=Request failed: internal server error (500), com.alamofire.serialization.response.error.data=<3c6e7331 3a584d4c 4661756c 7420786d 6c6e733a 6e73313d 22687474 703a2f2f 6378662e 61706163 68652e6f 72672f62 696e6469 6e67732f 78666f72 6d617422 3e3c6e73 313a6661 756c7473 7472696e 6720786d 6c6e733a 6e73313d 22687474 703a2f2f 6378662e 61706163 68652e6f 72672f62 696e6469 6e67732f 78666f72 6d617422 3e6a6176 612e6c61 6e672e4e 756c6c50 6f696e74 65724578 63657074 696f6e3c 2f6e7331 3a666175 6c747374 72696e67 3e3c2f6e 73313a58 4d4c4661 756c743e>, NSUnderlyingError=0x1757d4c0 "Request failed: unacceptable content-type: text/xml"}
上記のコード行は、NSString * jsonString = @ "{\" path \ "/ \" value \ ":{\" state \ ":\" ACTIVE \ "}、\" op \ ":\" replace \ "}]"; NSData * postBodyData = [NSData dataWithBytes:[jsonString UTF8String] length:[jsonString length]]; ' –