I've built an iOS app that hits my custom Django server. I am using AlamoFire to make the HTTP requests. The following is my code in Swift that I got from here (note that url
is a variable I created beforehand with the correct path).
let headers: HTTPHeaders = ["Authorization" : accessToken, "Content-Type" : "application/json"]
AF.request(url,
method: .get,
parameters: params,
encoding: URLEncoding.default,
headers: headers,
interceptor: nil).validate().responseJSON { response in
switch response.result {
case .success:
if let json = response.value as? [String : AnyObject] {
completion?(json, nil)
}
case .failure(let error):
completion?(nil, error)
}
}
However, when I try to get my authorization token on my Django server like so (which I found from here):
request.META.get("HTTP_AUTHORIZATION")
I get None
as the return type. I'm rather new to using Alamofire and also Django so I am unsure as to where the problem lies. I've tried looking up solutions for both the iOS and the Django side, but to no avail.
As a side note, I used to work on a project using Flask and was able to get the Authorization
header like so:
request.headers.get('Authorization')