Does the popular open-source framework AFNetworking have a mechanism for logging requests/responses to console?
-
12-11-2019 - |
質問
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.
解決
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!
所属していません StackOverflow