Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the popular open-source framework AFNetworking have a mechanism for logging requests/responses to console?

I'd like to pump out the raw-ish HTTP requests/responses to the console to aid debugging.

I've looked at the various docs on GitHub and had a quick search through the code and couldn't find anything obvious, so I'm guessing the answer is no. But just wanted to check if I have missed anything obvious.

like image 443
Damien Avatar asked Jan 23 '12 19:01

Damien


1 Answers

AFURLConnectionOperation sends notifications when operations start and end. You can easily log requests by listening for those notifications and logging the notification object:

[[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingOperationDidStartNotification
                                                  object:nil
                                                   queue:nil
                                              usingBlock:^(NSNotification *note) {
                                                NSLog(@"Operation Started: %@", [note object]);
                                              }];

Combine with FormatterKit's TTTURLRequestFormatter for best results!

like image 176
mattt Avatar answered Oct 30 '22 14:10

mattt