无法通过标头中的Api密钥进行身份验证

时间:2019-09-11 09:41:40

标签: swift restful-authentication

我试图访问一个宁静的API,但我似乎无法使授权标头正常工作 它可以卷曲。 here's the documentation

var request = URLRequest(url: URL(string: "https://api-eu.dhl.com/track/shipments?trackingNumber=JJD000390011905333749")!)
request.addValue("DHL-API-Key: bliblablubbnotrealkey", forHTTPHeaderField: "Authorization")
request.httpMethod = "GET"
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

URLSession.shared.dataTask(with: request) { data, response, error in
    print(response!)
    do {
        let json = try JSONSerialization.jsonObject(with: data!) as! Dictionary<String, AnyObject>
        print(json)
    } catch {
        print("error")
    }
}.resume()

0 个答案:

没有答案