3 ms·
Is there any way to add custom HTTP header yet? This would make for a nice API: Alamofire.request(.GET, "http://httpbin.org/get") .header("custom-
by Void_ 12y ago
Is there any way to add custom HTTP header yet? This would make for a nice API:
Alamofire.request(.GET, "http://httpbin.org/get")
.header("custom-header", "value")
- matttthompson 12y agoThe short answer: Use the version of `request` that takes a `URLRequestConvertible`, and specify the header fields in that. The long answer: Custom headers on a per-request basis are a bit of a red herring, from an API design perspective. In reality, most use cases boil down to one of three, which are taken care of in other ways: - Default headers, such as `User-Agent`, are specified in `NSURLSessionConfiguration -HTTPAdditionalHeaders`. - `Authorization` headers, which are handled by `NSURLCredential` and `NSURLAuthenticationChallenge`. - `Content-Type` headers, which are handled by `ParameterEncoding`. This is why Alamofire is designed the way it is.