Created
September 20, 2012 06:26
-
-
Save simonpang/3754256 to your computer and use it in GitHub Desktop.
Debug network connections using AFNetwork
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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