Created
April 16, 2013 09:18
-
-
Save tibo/5394580 to your computer and use it in GitHub Desktop.
print Curl request from an NSURLRequest for replay/debug purposes
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
@implementation NSURLRequest (printCurlRequest) | |
-(NSString *)curlRequest | |
{ | |
__block NSString *curlstr = [NSString stringWithFormat:@"curl -k -X %@ --dump-header -",self.HTTPMethod]; | |
[[self allHTTPHeaderFields] enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { | |
curlstr = [curlstr stringByAppendingFormat:@" -H \"%@: %@\"",key, obj]; | |
}]; | |
NSString *data = [[NSString alloc] initWithData:self.HTTPBody encoding:NSUTF8StringEncoding]; | |
if (data) | |
{ | |
curlstr = [curlstr stringByAppendingFormat:@" -d \"%@\"",data]; | |
} | |
curlstr = [curlstr stringByAppendingFormat:@" %@",self.URL.absoluteString]; | |
return curlstr; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment