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

  1. //
  2. // FLEXCurlLogger.m
  3. //
  4. //
  5. // Created by Ji Pei on 07/27/16
  6. //
  7. #import "FLEXNetworkCurlLogger.h"
  8. @implementation FLEXNetworkCurlLogger
  9. + (NSString *)curlCommandString:(NSURLRequest *)request {
  10. __block NSMutableString *curlCommandString = [NSMutableString stringWithFormat:@"curl -v -X %@ ", request.HTTPMethod];
  11. [curlCommandString appendFormat:@"\'%@\' ", request.URL.absoluteString];
  12. [request.allHTTPHeaderFields enumerateKeysAndObjectsUsingBlock:^(NSString *key, NSString *val, BOOL *stop) {
  13. [curlCommandString appendFormat:@"-H \'%@: %@\' ", key, val];
  14. }];
  15. NSArray<NSHTTPCookie *> *cookies = [NSHTTPCookieStorage.sharedHTTPCookieStorage cookiesForURL:request.URL];
  16. if (cookies) {
  17. [curlCommandString appendFormat:@"-H \'Cookie:"];
  18. for (NSHTTPCookie *cookie in cookies) {
  19. [curlCommandString appendFormat:@" %@=%@;", cookie.name, cookie.value];
  20. }
  21. [curlCommandString appendFormat:@"\' "];
  22. }
  23. if (request.HTTPBody) {
  24. [curlCommandString appendFormat:@"-d \'%@\'", [NSString stringWithCString:request.HTTPBody.bytes encoding:NSUTF8StringEncoding]];
  25. }
  26. return curlCommandString;
  27. }
  28. @end