这就是我的情况
我有一个参数列表
let body: Parameters = [
"name": "Sample Name"]
我使用 alamofire
发送这个主体变量:
Alamofire.request(BASE_URL",method: .post,parameters: body,encoding: JSONEncoding.default).responseData { response in
debugPrint("All Response Info: \(response)")
//printing the body just to see what it is sending and everything is as it should be
print(body)
if let data = response.result.value, let utf8Text = String(data: data, encoding: .utf8) {
print("Data: \(utf8Text)")
}
}
问题是响应是一个 400 bad request
响应,并带有错误消息 name is required
。这是 api
中必需的,但是由于某种原因,我猜 alamofire
没有正确发送。为什么会发生这种情况以及如何修复它?
最佳答案
根据 API 文档,您可能希望将编码类型更改为 URLEncoding,如下所示:-
URLEncoding.default
关于swift - Alamofire 未正确发送请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57510846/