在POSTMAN和Swift中尝试从API获得不同的响应

时间:2018-07-03 08:08:13

标签: ios swift api alamofire postman

我正在尝试使用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."
}

enter image description here

0 个答案:

没有答案