简体   繁体   English

调试Alamofire请求

[英]Debugging Alamofire request

I'm trying to debug the HTTP header & body that's sent to a server endpoint by Alamofire. 我正在尝试调试由Alamofire发送到服务器端点的HTTP标头和正文。 All the header parameters seem to be correct as I get an acknowledgement from the endpoint I'm dealing with, however, I'm having trouble with the server, the JSON I'm sending to it in the parameters field isn't being parsed. 所有的头参数似乎都是正确的,因为我得到了我正在处理的端点的确认,但是,我遇到了服务器的问题,我在参数字段中发送给它的JSON没有被解析。 How can I find out what's being sent in the request? 如何找出请求中发送的内容?


let headers: HTTPHeaders = [
                    "API-Key": apiKey,
                    "Accept": "application/json",
                    "Content-Type": "application/json"
                ]

let data = ["name":"Don Jonhson"]


Alamofire.request(endPointUrl, method: .post,  parameters: data, 
encoding: URLEncoding.httpBody, headers: headers).responseJSON() { 
           response in

           if let status = response.response?.statusCode {
              switch(status){
               case 201:
                debugPrint(response)
               default:
                debugPrint(response)
              }
           }

          ...

You're using a simple string dictionary you have to use alamofire's parameters instead 您正在使用简单的字符串字典,而不是使用alamofire的参数

let params: Parameters = ["name":"Don Jonhson"]

Alamofire.request(endPointUrl, method: .post,  parameters: params, 
encoding: URLEncoding.httpBody, headers: headers).responseJSON() { 
       response in

       if let status = response.response?.statusCode {
          switch(status){
           case 201:
            debugPrint(response)
           default:
            debugPrint(response)
          }
       }

      ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM