I implemented a POST request with Alamofire
with a custom header, because we work with OAuth2 and we have to send an access token in every request inside the header. In this case I have to use a custom header.
The access token value for the HTTP header field Authorization
does not work for me. The server generates an error because the header information for OAuth with the access token is not available.
But what is the mistake in my code?
Here is my current code:
let URL = NSURL(string: url + "/server/rest/action")
var mutableURLRequest = NSMutableURLRequest(URL: URL!)
mutableURLRequest.setValue("Bearer \(accessToken)", forHTTPHeaderField: "Authorization")
//this method does not work anymore because it returns an error in the response
//Alamofire.Manager.sharedInstance.session.configuration.HTTPAdditionalHeaders = ["Authorization": "Bearer \(accessToken)"]
Alamofire.Manager.sharedInstance
.request(.POST, mutableURLRequest, parameters: parameters, encoding: .JSON)
.validate()
.responseJSON {
(request, response, data, error) -> Void in
NSLog("REQUEST: \(request)")
NSLog("RESPONSE: \(response)")
NSLog("DATA: \(data)")
NSLog("ERROR: \(error)")
}