Skip to content

Instantly share code, notes, and snippets.

@MKSG-MugunthKumar
Created May 5, 2015 04:05
Show Gist options
  • Save MKSG-MugunthKumar/5cda35464a93c7aca378 to your computer and use it in GitHub Desktop.
Save MKSG-MugunthKumar/5cda35464a93c7aca378 to your computer and use it in GitHub Desktop.
NSURLRequest cURL description
- (NSString *)description {
__block NSMutableString *displayString = [NSMutableString stringWithFormat:@"curl -v -X %@", self.HTTPMethod];
[displayString appendFormat:@" \'%@\'", self.URL.absoluteString];
[self.allHTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(id key, id val, BOOL *stop) {
[displayString appendFormat:@" -H \'%@: %@\'", key, val];
}];
if ([self.HTTPMethod isEqualToString:@"POST"] ||
[self.HTTPMethod isEqualToString:@"PUT"] ||
[self.HTTPMethod isEqualToString:@"PATCH"]) {
[displayString appendFormat:@" -d \'%@\'",
[[NSString alloc] initWithData:self.HTTPBody encoding:NSUTF8StringEncoding]];
}
return displayString;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment