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);
}];
It's the other way round... this should do it