Using below curl command I am able to get a valid response with required token.
curl -v -h "TOKEN:tokenValue" @“someurl.com”
However, When I try to create a NSMutableURLRequest as shown below, I get a different response.
NSURL* url = [NSURL URLWithString:kURL];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:url];
[urlRequest addValue:tokenValueStr forHTTPHeaderField:@"TOKEN"];
[urlRequest setHTTPMethod:@"GET"];
[NSURLConnection sendAsynchronousRequest:urlRequest
queue:[NSOperationQueue mainQueue]
completionHandler:handler];
I have checked the [request allHTTPHeaderfields] and it shows dictionary with TOKEN key-value pair. and Token and url are valid URLs. Theoretically this request is what I am supposed to get the right response but it isnt and I did not find any useful reference online either. Any suggestions are appreciated.
When you pass a header into curl, you must give the name and value of the header like this:
For the Objective-C parameter, you are passing in a value and a name. The value should just be "HeaderValue" and the name would be "HeaderName", which is "TOKEN" in this case.