我正在尝试使用Authorization标头访问GET
API,但得到不同的响应:
快速查看:
{
error = "access_denied";
"error_description" = "OAuth2 authentication required";
}
迅速:
var urlString = "http://exaple.com/ser/2521"
urlString = urlString.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)!
let url = URL(string: urlString)
let headers: HTTPHeaders = [
"Authorization": "Bearer " + self.oAuthToken.access_token!
, "Accept": "application/json"
]
Alamofire.request(url!, method: HTTPMethod.get, parameters: nil, encoding: URLEncoding.default, headers: headers) .responseJSON { (response) in
switch response.result {
case .success(let data):
guard let response = data as? [String: Any] else {
return
}
print(response)
case .failure(let error):
print(error.localizedDescription)
}
}
来自POSTMAN:
响应为:
{
"code": 400,
"message": "Reservation failed."
}