Here's an example of how I use it with custom headers:
var manager = Manager.sharedInstance
// Specifying the Headers we need
manager.session.configuration.HTTPAdditionalHeaders = [
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/vnd.lichess.v1+json",
"X-Requested-With": "XMLHttpRequest",
"User-Agent": "iMchess"
]
Now whenever you make a request, it'll use the specified headers.
Your code refactored:
remember to import Alamofire
let aManager = Manager.sharedInstance
manager.session.configuration.HTTPAdditionalHeaders = [
"Authorization": "Bearer (accessToken)" ]
let URL = url + "/server/rest/action"
request(.POST, URL, encoding: .JSON)
.responseJSON {
(request, response, data, error) -> Void in
println("REQUEST: (request)")
println("RESPONSE: (response)")
println("DATA: (data)")
println("ERROR: (error)")
}
This is request signature request(method: Method, URLString: URLStringConvertible>, parameters: [String : AnyObject]?, encoding: ParameterEncoding)
As you can see you don't have to pass an NSURL in it, just the string of the URL, Alamofire takes care of the rest.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…