当我通过邮递员设置内容类型标头和具有确切值的标头时,我有一个 sylius API的请求端点,它可以很好地响应预期的响应,但是当我尝试通过它设置请求授权标头时,它会给我一个响应application/json
Authorization
Bearer SampleToken
URLRequest
{
error = "access_denied";
"error_description" = "OAuth2 authentication required";
}
当我通过 charles 监控请求时,我注意到Authorization
标头已被剥离。我尝试了许多不同的方法来设置授权标头,但没有运气。
func getTotalProducts(page:String){
let urlPath="https://demo.sylius.com/api/v2/products"
var request = URLRequest(url: NSURL(string: urlPath)! as URL)
request.httpMethod = "GET"
request.setValue("Bearer SampleToken", forHTTPHeaderField: "Authorization")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
Alamofire.request(request)
.responseJSON { response in
switch(response.result){
case .success(let value):
print(value)
break
case .failure(let error):
print("something went wrong \(error.localizedDescription)")
}
}.session.finishTasksAndInvalidate()
}
原始邮递员请求: