Swift Alamofire add custom header to all requests

前端 未结 4 1773
北荒
北荒 2021-01-12 11:13

I tried to add custom header with this:

let manager = Manager.sharedInstance
manager.session.configuration.HTTPAdditionalHeaders = [
    \"Authorization\": \         


        
4条回答
  •  星月不相逢
    2021-01-12 11:44

    You should not append Authorization headers in this way. They should always be appended using the headers parameter in the request method as shown by @Glenn.

    Additionally, if you need to append other headers to a configuration, you need to create a custom configuration, set the header values, then create a new Manager instance with the new configuration. Adding headers to a configuration after it has already been used to create a URL session results in undefined behavior depending on which version of which OS you are running on. We have many tests in Alamofire demonstrating this varying behavior.

提交回复
热议问题