我正在请求一个 JSON-API,如下所示:
var request = URLRequest(url: url)
request.httpMethod = "GET"
request.addValue(CredentialsProvider.shared.credentials, forHTTPHeaderField: "Authorization")
let task = URLSession.shared.dataTask(with: request as URLRequest) { data, response, error in
guard let data = data, let _ = response, error == nil else {
return
}
let response1 = response as! HTTPURLResponse
print(response1.statusCode) // 200 instead of 304
}
由于服务器进行缓存(我通过 CharlesProxy 验证),我希望状态码 304 但记录了 200 - 有没有办法获得“真实”状态码?