Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift Alamofire add custom header to all requests

I tried to add custom header with this:

let manager = Manager.sharedInstance
manager.session.configuration.HTTPAdditionalHeaders = [
    "Authorization": "Token \(token)"
]

But it doesn't work, what am i doing wrong?

I need to add this after login, so that header will be used in all requests.

like image 322
Mirza Delic Avatar asked Sep 24 '15 09:09

Mirza Delic


2 Answers

A way to do this is to use a RequestAdapter as demoed on the Alamofire advanced usage documentation.

like image 122
Alexis Avatar answered Sep 20 '22 00:09

Alexis


I don't know where you do that but my AlomoFire requests look like :

 Alamofire.request(.GET, urlPath, parameters: parameters, headers: ["X-API-KEY": apiKey, "Content-type application":"json", "Accept application" : "json"]).responseJSON() { (req,res, data, error) in //blah blah }

My guess is that you can put your header information into that headers array

like image 45
Glenn Avatar answered Sep 22 '22 00:09

Glenn