Hi, I have problem implementing POST request in Swift 3.0.
How to pass header in this request:
Alamofire.request("\(apiUrl)", method: .post, parameters: parameters)
.validate(statusCode: 200..<205)
.responseString { response in
When I put header next to "parameters" I'm getting error "Extra argument 'method' in call"
My header is:
let headers: HTTPHeaders = [ "X-APP-TOKEN" : Token().readToken() ]
My bad. It should be after parameters, not before :-)
It was before parameters on earlier version.
I have the same error with header on the right... Any other advice?
FYI: url: String, parameters: [String: String], header: HTTPHeaders
Alamofire.request(url, method: .post, parameters: parameters, encoding: .JSON, headers: headers).responseJSON { (response) in }
Me too! How do I pass the headers on a post?
Hi scottrichards,
You can pass header as below, make sure you are using latest version of Alamofire ->4 and swift 3.0
Its working fine for me. Hope it helps :)
Alamofire.request("your_URL", parameters: your_parameters, headers: ["accessToken": "your app token", "Content-type application":"json", "Accept application" : "json"]).responseJSON() { response in }
I also having the same problem..I sending
let headers : HTTPHeaders = [ "Content-Type":"application/x-www-form-urlencoded",authorization" : apiKey ]
Alamofire.request(AppConfig.MyUrl,method: .post ,parameters : params,encoding: JSONEncoding.default ,headers:headers).responseJSON {response in
But the value of authorization cannot get in my webservice.Please help
Most helpful comment
I have the same error with header on the right... Any other advice?
FYI:
url: String, parameters: [String: String], header: HTTPHeadersAlamofire.request(url, method: .post, parameters: parameters, encoding: .JSON, headers: headers).responseJSON { (response) in }