AFNetworking journal query request for multipart / form data

Say I have multipart / form data built below

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    NSDictionary *parameters = @{@"foo": @"bar"};
    NSURL *filePath = [NSURL fileURLWithPath:@"file://path/to/image.png"];
    [manager POST:@"http://example.com/resources.json" parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
        [formData appendPartWithFileURL:filePath name:@"image" error:nil];
    } success:^(AFHTTPRequestOperation *operation, id responseObject) {
        NSLog(@"Success: %@", responseObject);
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Error: %@", error);
    }];

This is what AFNetworkActivityLogger writes. Body (null).

POST 'http://example.com/resources.json': {
    "Accept-Language" = "en;q=1, fr;q=0.9, de;q=0.8, zh-Hans;q=0.7, zh-Hant;q=0.6, ja;q=0.5";
    "Content-Length" = 206123;
    "Content-Type" = "multipart/form-data; boundary=Boundary+A13DFC7B7D81B98A";
    "User-Agent" = "Example/0.2.3 (iPad Simulator; iOS 8.3; Scale/2.00)";
} (null)

How can I register the request body sent to the API?

+4
source share
1 answer

AFNetworkActivityLogger does not display the body of the multipart form request, because the request does not have the HTTPBody property, instead it has an HTTPBodyStream. See here:

https://github.com/AFNetworking/AFNetworkActivityLogger/blob/master/AFNetworkActivityLogger/AFNetworkActivityLogger.m#L120

To check the request body, follow these steps:

: com.alamofire.networking.task.resume : NSURLRequest * request = AFNetworkRequestFromNotification (); : [request HTTPBodyStream]

0

Source: https://habr.com/ru/post/1583808/


All Articles