Question

I am putting together a string with certain content, that is set as an HTTP header field of NSMutableURLRequest:

NSString *authenticationHeaderString = [NSString stringWithFormat:@"OAuth oauth_callback=\"%@\", oauth_nonce=\"%@\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"%@\", oauth_consumer_key=\"xxxxxxxxx\", oauth_signature=\"%@\", oauth_version=\"1.0\"", [callbackURLString URLEncodedString], nonce, timestampString, [BYOAuthSignatureString signatureStringWithParameters:signingParams URL:[mURLRequest.URL absoluteString] HTTPMethod:mURLRequest.HTTPMethod]];
NSLog(@"authenticationHeaderString: %@", authenticationHeaderString);
[mURLRequest setValue:[NSString stringWithFormat:@"%@", authenticationHeaderString] forHTTPHeaderField:@"Authorization"];
NSLog(@"header:%@", mURLRequest.allHTTPHeaderFields);

In the header field the \" is not converted into "

authenticationHeaderString: OAuth oauth_callback="http%3A%2F%2Fbytolution.com", oauth_nonce="o7QNfKOMBKtdZQmJrbV9QWqVwUkkRK1ABbjfK4hWTQ", oauth_signature_method="HMAC-SHA1", oauth_timestamp="1361735323", oauth_consumer_key="xxxxxxxxxxx", oauth_signature="koNYscKJx3WwC7M4kHsrMpfzYoo=", oauth_version="1.0"

header:{ Authorization = "OAuth oauth_callback=\"http%3A%2F%2Fbytolution.com\", oauth_nonce=\"o7QNfKOMBKtdZQmJrbV9QWqVwUkkRK1ABbjfK4hWTQ\", oauth_signature_method=\"HMAC-SHA1\", oauth_timestamp=\"1361735323\", oauth_consumer_key=\"xxxxxxxxxxxx\", oauth_signature=\"koNYscKJx3WwC7M4kHsrMpfzYoo=\", oauth_version=\"1.0\""; }

Why is that?

Was it helpful?

Solution

This is just the way that the NSDictionary mURLRequest.allHTTPHeaderFields is printing itself. Whenever NSDictionaries print their contents they double-quote any strings that include a space. They also escape any double-quotes in the string, among other things.

The string has not been changed. You can verify this by doing

NSLog(@"authHeader: %@", [mURLRequest.allHTTPHeaderFields objectForKey: @"Authorization"]);

OTHER TIPS

It is converted... But then it is converted back for displaying.

Your header should be fine, just it is displayed as a string for logging.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top