Skip to content

Instantly share code, notes, and snippets.

@tibo
Created April 16, 2013 09:18
Show Gist options
  • Save tibo/5394580 to your computer and use it in GitHub Desktop.
Save tibo/5394580 to your computer and use it in GitHub Desktop.
print Curl request from an NSURLRequest for replay/debug purposes
@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