Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Authorization header not sent for GET method in swift 3 #2193

Closed
Vaisakh-Mohan opened this issue Jul 5, 2017 · 5 comments

Comments

@Vaisakh-Mohan
Copy link

commented Jul 5, 2017

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 Environment

Alamofire version:4.5.0
Xcode version:8.3.3
Swift version:3

macOS version : macOS Sierra 10.12.5

@jshier

This comment has been minimized.

Copy link
Contributor

commented Jul 10, 2017

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.

@jshier jshier closed this Jul 10, 2017
@jshier jshier self-assigned this Jul 10, 2017
@jshier jshier added the support label Jul 10, 2017
@neoMarker

This comment has been minimized.

Copy link

commented Aug 28, 2017

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
]

@baderSader

This comment has been minimized.

Copy link

commented Oct 11, 2017

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

@ermik

This comment has been minimized.

Copy link

commented Dec 7, 2018

Can I add @baderSader's explanation to a FAQ somewhere? cc @jshier

@lahmacun

This comment has been minimized.

Copy link

commented Sep 21, 2019

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.