3

I can't seem to get my networking code to work. I've spent at least a couple hours looking through documentation and Google this over the last 2 days and I can't figure it out. For whatever reason, it appears my NSURLSession isn't sending along the headers. I preformed the proper request in Postman for Chrome and am using those exact parameters so I know I'm not sending incorrect data. I continue to get an error that I was able to reproduce in Postman by removing header parameters.

Code:

NSURLSessionConfiguration *sessionConfig = [NSURLSessionConfiguration defaultSessionConfiguration];

NSDictionary *sessionHeaders = [[NSDictionary alloc] initWithObjectsAndKeys:
@"application/json", @"Accept", @"application/xml", @"Content-Type", 
[NSString stringWithFormat:@"LivePerson appKey=%@", self.getAppKey], @"Authorization", nil];

sessionConfig.HTTPAdditionalHeaders = sessionHeaders;

NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfig];

NSURLSessionDataTask *endpoints = [session dataTaskWithURL:[NSURL URLWithString:baseURL] 
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

NSDictionary *endpoints = [NSJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSLog(@"%@", endpoints);
}];
Tulon
  • 4,011
  • 6
  • 36
  • 56
  • First thing I'd try is to confirm the problem is what you think it is by using a debugging proxy server to dump the request (e.g. something like [Charles](http://www.charlesproxy.com).) This will mean you're not guessing about what's wrong, but will be able to compare the requests from Chrome and from your NSURLSession code side-by-side. – Matt Gibson May 26 '14 at 07:03

1 Answers1

0

It's the other way round... this should do it

NSDictionary *sessionHeaders = [[NSDictionary alloc] initWithObjectsAndKeys:
@"Accept", @"application/json", @"Content-Type", @"application/xml",  
@"Authorization", [NSString stringWithFormat:@"LivePerson appKey=%@", self.getAppKey], nil];
Yoel Garcia
  • 163
  • 1
  • 8