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

StackOverflow https://stackoverflow.com/questions/8977641

  •  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!

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top