Alamofire - 获得身体反应

时间:2018-04-19 17:39:27

标签: swift alamofire

我疯狂地试图找到一种方法来获取服务器响应,就像服务器从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?
             .
             .
             .

1 个答案:

答案 0 :(得分:2)

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.allHeaderFieldsdata中的原始内容正文中找到回复标题。