Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I log AFHTTPRequestOperationManager request?

I'm having some trouble with RESTfull web service and I'm trying to see my request as a text using NSLog. I tried this:

AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
...
 [manager POST:urlString parameters:mutableParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {
...
   } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Response:  %@", [operation description]) ;
        if (block) {
            block(error);
        }

        NSLog(@"-------------------------------");
        NSLog(@"Request: %@", manager.requestSerializer.debugDescription);
        NSLog(@"-------------------------------");
        NSLog(@"Request: %@", manager.requestSerializer.description);
        NSLog(@"-------------------------------");
        NSLog(@"Request: %@", operation.request.HTTPBodyStream);
        NSLog(@"-------------------------------");
        NSLog(@"Request: %@", operation.request);
        NSLog(@"-------------------------------");
        NSLog(@"Error: %@", error);
        NSLog(@"-------------------------------");

}];

Is there any way to NSLog the request from AFHTTPRequestOperationManager (AFNetworking 2) ?

like image 322
Sebastian Avatar asked Feb 02 '26 07:02

Sebastian


1 Answers

Have a look to the POST method:

 [manager POST:urlString parameters:mutableParameters success:^(AFHTTPRequestOperation *operation, id responseObject) {

You have a AFHTTPRequestOperation *operation and an id responseObject in the success block.

The best thing that you can do is to put a:

NSLog(@"AFHttpRequestOperation %@", operation);

and set there a breakpoint so you can inspect what's happening there:

enter image description here

What do you want to see about the operation's request?

Not exactly logging but this answer explains how to convert NSURLRequest to NSString

like image 80
javierfdezg Avatar answered Feb 04 '26 20:02

javierfdezg



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!