Skip to content

Instantly share code, notes, and snippets.

@simonpang
Created September 20, 2012 06:26
Show Gist options
  • Save simonpang/3754256 to your computer and use it in GitHub Desktop.
Save simonpang/3754256 to your computer and use it in GitHub Desktop.
Debug network connections using AFNetwork
- (void)enableNetworkDebug {
[[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingOperationDidStartNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
AFHTTPRequestOperation *op = [note object];
NSLog(@"\n\nREQUEST:%x \n%@\n\n", (NSUInteger)op.request, [TTTURLRequestFormatter cURLCommandFromURLRequest:op.request]);
}];
[[NSNotificationCenter defaultCenter] addObserverForName:AFNetworkingOperationDidFinishNotification
object:nil
queue:nil
usingBlock:^(NSNotification *note) {
AFHTTPRequestOperation *op = [note object];
TTTHTTPURLResponseFormatter *formatter = [[TTTHTTPURLResponseFormatter alloc] init];
NSLog(@"\n\nRESPONSE:%x\n %@\n%@\n", (NSUInteger)op.request, [formatter stringFromHTTPURLResponse:op.response], op.responseString);
}];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment