我当前的代码显示标题信息,但是我希望正文响应。我正在尝试获取令牌以用于其他请求。
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()
答案 0 :(得分:1)
响应的内容位于data
的完成块的dataTask(with: request)
变量中。