如何从服务器获取AFNetworking中的完整响应字符串?

时间:2017-04-22 07:21:55

标签: ios swift afnetworking afnetworking-3

我正在使用AFNetworking 3.0与session manager这样:

    sessionManager = AFHTTPSessionManager(baseURL: baseURL)
    sessionManager?.post(url, parameters: parameters, progress: nil,
                         success: {(task: URLSessionDataTask, responseObject: Any) in
                           print(task?.response)
                         , failure: {(task: URLSessionDataTask?, error: Error) in
                         print(task?.response)
    })

当我打印task.response对象时,我只得到标题。如何从服务器获取完整的响应字符串和错误(如果有的话)?

1 个答案:

答案 0 :(得分:0)

你可以试试这个

    print(responseObject.response)
    print(responseObject.response.request)  // original URL request
    print(responseObject.response.response) // URL response
    print(responseObject.response.data)     // server data
    print(responseObject.response.result)   // result of response serialization