I am sending bearer token in header which is working for post method. The code below is I am using for POST method
let parameters: Parameters = [
"key1":"Value1",
"key2":"value2"
]
let headers = [
"Authorization": "Bearer "+loginkey!
]
Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding.httpBody,headers: headers).responseJSON
{
response in
debugPrint(response)
}
for GET method I am using below code
let headers = [
"Authorization": "Bearer "+loginkey!
]
Alamofire.request(url, method: .get, headers: headers).responseJSON
{
response in
debugPrint(response)
}
but I always get response as unauthorized. i have checked the server log,it doesn't receive http header I am sending.
what is wrong with Alamofire here?
Alamofire version:4.5.0
Xcode version:8.3.3
Swift version:3
macOS version : macOS Sierra 10.12.5
I would suggest using a proxy tool like Charles Proxy to check what you're actually sending vs. what you're seeing in the server logs. We have extensive tests around this scenario so it's unlikely there's an issue within Alamofire. However, if your investigation does reveal an Alamofire bug, let us know and we can reopen this issue.
I had the same issue, Not sure if its an Alamofire or Swift 3 issue.
But i could resolve this simply by changing the key name "Auth" key istead of "Authentication"
let auth_code = [
"Auth": MY_API_KEY
]
There is No Issue In This,
please check your api url string as if you write the url as
http://example.com/test/
instead if
http://example.com/test
your request will be redirected to the correct one and the Authorization header will not included in redirect for security issues
@jshier I suggest to add method for rewrite the url and query string before calling to ignore such issues
Can I add @baderSader's explanation to a FAQ somewhere? cc @jshier
There is No Issue In This,
please check your api url string as if you write the url as
http://example.com/test/
instead if
http://example.com/test
your request will be redirected to the correct one and the Authorization header will not included in redirect for security issues@jshier I suggest to add method for rewrite the url and query string before calling to ignore such issues
You're my hero, thank you so much! You're awesome 馃榿 I was going to lose my mind, until I find your answer. Thank you so muchhh!
There is No Issue In This,
please check your api url string as if you write the url as
http://example.com/test/
instead if
http://example.com/test
your request will be redirected to the correct one and the Authorization header will not included in redirect for security issues
@jshier I suggest to add method for rewrite the url and query string before calling to ignore such issuesYou're my hero, thank you so much! You're awesome 馃榿 I was going to lose my mind, until I find your answer. Thank you so muchhh!
hi @lahmacun, did u solve this?
What is the solution of problem?
Most helpful comment
There is No Issue In This,
please check your api url string as if you write the url as
http://example.com/test/
instead if
http://example.com/test
your request will be redirected to the correct one and the Authorization header will not included in redirect for security issues
@jshier I suggest to add method for rewrite the url and query string before calling to ignore such issues