Updated Alamofire from 4.x to 5.0.0 beta 2
Everything works
There were SessionManager.defaultHTTPHeaders. Now it doesn't exist and there is no info what and how to use instead. Of course I can't even compile the project
Alamofire version: 5.0.0 beta 2
Xcode version: 10.1
Swift version: 4
Platform(s) running Alamofire: iOS
macOS version running Xcode: 10.14.3
Alamofire 5 now has an HTTPHeaders type, which has a default static property for the the default headers.
@jshier I have tried like the one below but it did not work.Can you please help?configuration.httpAdditionalHeaders = HTTPHeaders.default
configuration.headers = .default // not httpAdditionalHeaders, it's Alamofire 4
You can also use HTTPHeaders.default.dictionary if you want to get dictionary of default headers as it was in Alamofire 4.
You can also start with the Alamofire URLSessionConfiguration and not have to add our headers at all:
let configuration = URLSessionConfiguration.af.default
This configuration is the same as URLSessionConfiguration.default, but also includes our default headers.
Otherwise, we also have an extension on URLSessionConfiguration to work with Alamofire's HTTPHeaders type:
let configuration = URLSessionConfiguration.default
configuration.headers = .default
Swift 5 with Alamofire 5:
var headers = AF.session.configuration.headers
That's incorrect: you should use HTTPHeaders.default if you want our default set of headers, or URLSessionConfiguration.af.default if you want a URLSessionConfiguration with our defaults headers already added.
In my case I replaced SessionManager.defaultHTTPHeaders["User-Agent"] by HTTPHeader.defaultUserAgent.value.
Most helpful comment
Alamofire 5 now has an
HTTPHeaderstype, which has adefaultstatic property for the the default headers.