从post请求中检索标头值

时间:2016-03-05 00:06:39

标签: ios swift alamofire

我尝试从标头响应中检索值,但似乎无法检索此值?我曾尝试使用allHeaderFields,但似乎不是NSURLResponse的成员?

testProvider.request(.SignIn(email, password), completion: { result in
    switch result {
    case let .Success(response):

        do {
            try response.filterSuccessfulStatusCodes()
            let data = try response.mapJSON()



        }
        catch {
            // show an error to your user
        }

    case let .Failure(error):
        print(error)

        let description = "Error! Please check your internet connection"
        delegate.loginProvider(self, didError: description)
    }

})

1 个答案:

答案 0 :(得分:0)

使用此闭包,您可以使用response?.allHeaderFields获得收到的标头。

    Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
        .response { request, response, data, error in
            print(request?.allHTTPHeaderFields)
            print(response?.allHeaderFields)
            print(data)
            print(error)
    }