我真的很难过。我需要将此 cURL 命令转换为objective-c。我正在使用 AFNetworking 库来解决这个问题,但它每次都返回错误的请求(错误 400)。我会很感激帮助。
卷曲命令:
curl -X POST -H "Content-Type: application/json" -H "Authorization: Bearer XXXXXXXXXXXXX" -d '{"quantity_delta": -5,"adjustment_type": "SALE"}' https://connect.squareup.com/v1/me/inventory/00CC0141-C50C-4A7A-9FAA-368EC79DA652
AFNetworking Objective-C 代码:
AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
[manager.requestSerializer setValue:@"Bearer XXXXXXXXXXXXX" forHTTPHeaderField:@"Authorization"];
[manager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
NSDictionary *parameters = @{@"quantity_delta": [NSNumber numberWithInt:-1], @"adjustment_type": @"SALE"};
NSLog(@"Parameters are %@", parameters);
[manager POST:@"https://connect.squareup.com/v1/me/inventory/00CC0141-C50C-4A7A-9FAA-368EC79DA652" parameters:@{@"quantity_delta": [NSNumber numberWithInt:-1], @"adjustment_type": @"SALE"} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSLog(@"JSON: %@", responseObject);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];