我试图访问一个宁静的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()