如何使用Alamofire在swift 3中打印http请求的正文

时间:2017-04-04 16:11:50

标签: ios swift httprequest alamofire

我正在尝试使用Alamofire在 swift 3 中使用 x-www-form-urlencoded 正文制作补丁请求,但它不起作用。我想打印请求的正文,这样我可以在邮递员提出请求时与结果进行比较。

这是我的代码

let parameters: [String:AnyObject] = ["conversation[emails_attributes][0][content]":text as AnyObject]

alamofireManager.request(URL, method: .patch, parameters: parameters, encoding: URLEncoding(destination: .httpBody), headers: headers)
    .response { httpResponse in
        if let error = httpResponse.error {
            print(error)
            completionHandler(.defaultFailResponse(NSLocalizedString("An errror has occurred",comment:"General Error Title")))
        } else {
            print("HTTP: \(httpResponse.response?.statusCode)")
            if let response = httpResponse.response{
                switch response.statusCode {

                case 200:
                    let jsonData = JSON(data: httpResponse.data!)
                    if (jsonData == nil) {
                        completionHandler(.defaultFailResponse(NSLocalizedString("Error on Data",comment:"Message error when data is null")))
                        return
                    }
                    print("Message Created")
                    completionHandler(.defaultSuccessResponse)
                default:
                    completionHandler(.defaultFailResponse(NSLocalizedString("Connection Error",comment:"Connection failed")))
                }
                print("Failed")
            }
        }
    }

我尝试过print("request body: \(request.HTTPBody)")但它不起作用,错误信息是

  

错误:对成员'请求的模糊引用(_:method:parameters:encoding:headers:)'

0 个答案:

没有答案