Armands Antans Armands Antans - 8 months ago 72
iOS Question

NSURLSessionConfiguration HTTPAdditionalHeaders not set

Authorization header is set in

, however it is not attached to
. Is this a bug in
Foundation framework

NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
[configuration setHTTPAdditionalHeaders:@{@"Authorization":@"123"}];

// Initialize session with NSURLSessionConfiguration
NSURLSession *session = [NSURLSession sessionWithConfiguration:configuration];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
NSURLSessionDataTask *sessionTask = [session dataTaskWithRequest:request
completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {

[sessionTask resume];


I try this in Swift and it works

    var sessionConfig = NSURLSessionConfiguration.defaultSessionConfiguration()
    var xHTTPAdditionalHeaders: [NSObject : AnyObject] = ["X-test":"taly"]
    sessionConfig.HTTPAdditionalHeaders = xHTTPAdditionalHeaders
    let session = NSURLSession(configuration: sessionConfig)

    let task = session.dataTaskWithURL(url, completionHandler: {data, response, error -> Void in