我正在尝试调试由 Alamofire 发送到服务器端点的 HTTP header 和正文。当我从正在处理的端点收到确认时,所有 header 参数似乎都是正确的,但是,我遇到了服务器问题,我在参数字段中发送给它的 JSON 没有被解析.我如何找出请求中发送的内容?
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)
}
}
...
最佳答案
您正在使用一个简单的字符串字典,您必须改用 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)
}
}
...
关于ios - 调试 Alamofire 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43263001/