Reputation: 21091
My app creates POST request with Authorization header - it looks like :
let accessToken = "veryCoolToken"
var request = URLRequest(url: myURL)
request.httpMethod = "POST"
request.addValue("application/json", forHTTPHeaderField: "content-type")
request.addValue("application/json", forHTTPHeaderField: "Accept")
request.setValue("token=\"\(accessToken)\"", forHTTPHeaderField: "Authorization")
I already checked this request with Postman app - it was fine. But for some reason I received needed result only from Postman and not from my app.
So after taking apart request on my Server - I found that when my app sending POST request - it is not "Authorization" but "authorization".
Why is that happening?
What else should I take in consideration when app sends POST request with headers?
Upvotes: 2
Views: 9149
Reputation: 9925
For POST requests in Swift, generally you have to set the following:
request.setValue("Basic " + accessToken, forHTTPHeaderField: "Authorization")
Upvotes: 3