阿拉莫火 - 获得body反应



我正在疯狂地试图找到一种方法来获取服务器响应,就像服务器从ResponseJSON闭包内部返回它一样。

 sessionManager!.request(urlPath, method: .post, parameters: nil, encoding: encoding, headers: nil).responseJSON 
       (dateRequest) in
            //How can I obtain the server reply, not encoded from here?
             .
             .
             .

requestJSON 将一个DataResponse<Any>实例传递给闭包,如下所示:

public struct DataResponse<Value> {
    /// The URL request sent to the server.
    public let request: URLRequest?
    /// The server's response to the URL request.
    public let response: HTTPURLResponse?
    /// The data returned by the server.
    public let data: Data?
    /// The result of response serialization.
    public let result: Result<Value>
    /// The timeline of the complete lifecycle of the request.
    public let timeline: Timeline
    /// Returns the associated value of the result if it is a success, `nil` otherwise.
    public var value: Value? { return result.value }
    /// Returns the associated error value if the result if it is a failure, `nil` otherwise.
    public var error: Error? { return result.error }
    // ...
} 

您可以在response.allHeaderFields中找到响应标头,在data中找到原始内容正文。

最新更新