我疯狂地试图找到一种方法来获取服务器响应,就像服务器从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?
.
.
.
答案 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.allHeaderFields
和data
中的原始内容正文中找到回复标题。