Because I dislike setting these things globally (and sometimes I send them, sometimes I don't), I wrote a wrapper method to set the headers with each call.
import Alamofire
public class Service: NSObject {
private class func request(method: Alamofire.Method, URLString: URLStringConvertible, parameters: [String : AnyObject]?, encoding: ParameterEncoding = .URL, headers: [String: String]? = nil) -> Request {
let (request, error) = encoding.encode(NSURLRequest(URL: NSURL(string: URLString.URLString)!), parameters: parameters)
let mutableURLRequest = request as! NSMutableURLRequest
mutableURLRequest.HTTPMethod = method.rawValue
if let heads = headers {
for (field, value) in heads {
mutableURLRequest.setValue(value, forHTTPHeaderField: field)
}
}
return Alamofire.request(mutableURLRequest)
}
}
It can be called as follows...
Service.request(.POST, URLString: "http://httpbin.org/post", parameters: ["example-param": "example-param-value"], encoding: .JSON, headers: ["example-header-field": "example-value"])/*.whatever you want to do with it*/
It could certainly be cleaned up with some error checking, but this should give you the gist of it. It's all based on Alamofire 1.2.