打印响应正文而不是标题

时间:2019-01-05 00:18:21

标签: swift nsurlsession

我当前的代码显示标题信息,但是我希望正文响应。我正在尝试获取令牌以用于其他请求。

    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()

1 个答案:

答案 0 :(得分:1)

响应的内容位于data的完成块的dataTask(with: request)变量中。