You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
1.2 KiB
37 lines
1.2 KiB
//
|
|
// FLEXCurlLogger.m
|
|
//
|
|
//
|
|
// Created by Ji Pei on 07/27/16
|
|
//
|
|
|
|
#import "FLEXNetworkCurlLogger.h"
|
|
|
|
@implementation FLEXNetworkCurlLogger
|
|
|
|
+ (NSString *)curlCommandString:(NSURLRequest *)request {
|
|
__block NSMutableString *curlCommandString = [NSMutableString stringWithFormat:@"curl -v -X %@ ", request.HTTPMethod];
|
|
|
|
[curlCommandString appendFormat:@"\'%@\' ", request.URL.absoluteString];
|
|
|
|
[request.allHTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *val, BOOL *stop) {
|
|
[curlCommandString appendFormat:@"-H \'%@: %@\' ", key, val];
|
|
}];
|
|
|
|
NSArray<NSHTTPCookie *> *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:request.URL];
|
|
if (cookies) {
|
|
[curlCommandString appendFormat:@"-H \'Cookie:"];
|
|
for (NSHTTPCookie *cookie in cookies) {
|
|
[curlCommandString appendFormat:@" %@=%@;", cookie.name, cookie.value];
|
|
}
|
|
[curlCommandString appendFormat:@"\' "];
|
|
}
|
|
|
|
if (request.HTTPBody) {
|
|
[curlCommandString appendFormat:@"-d \'%@\'", [[NSString alloc] initWithData:request.HTTPBody encoding:NSUTF8StringEncoding]];
|
|
}
|
|
|
|
return curlCommandString;
|
|
}
|
|
|
|
@end
|