我正在尝试从网站获取json,并且正在使用Swift。
为什么我只得到响应头而不是正文?
let headers = [
"auth": key,
"Cache-Control": "no-cache",
]
let request = NSMutableURLRequest(url: NSURL(string: url)! as URL,
cachePolicy: .useProtocolCachePolicy,
timeoutInterval: 10.0)
request.httpMethod = "GET"
request.allHTTPHeaderFields = headers
let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
if (error != nil) {
print(error!)
} else {
let httpResponse = response as? HTTPURLResponse
print(httpResponse!)
}
})
dataTask.resume()
我该如何解决?