【发布时间】:2020-04-27 18:19:29
【问题描述】:
{
"vUserList": [
{
"firstName": "Kate",
"lastName": "Bell",
"email": "katebell@mac.com"
},
{
"lastName": "Higgins",
"firstName": "Daniel",
"email": "dhiggins@mac.com"
},
{
"email": "JohnAppleseed@mac.com",
"firstName": "John",
"lastName": "Appleseed"
},
{
"lastName": "Haro",
"firstName": "Anna",
"email": "annaharo@mac.com"
},
{
"email": "hankzakroff@mac.com",
"firstName": "Hank",
"lastName": "Zakroff"
}
]
}
这是我需要发送到服务器的请求参数。
func getContactsParameters() -> [String : Any] {
return [Keys.vUserList : arrContacts]
}
var headers = [
Keys.XAPIKEY: "5dik8fo5yecc25bfcc562724dd674bde5fh5ju8y"
]
Alamofire.request("urlString", method: .post, parameters: getContactsParameters(), encoding: JSONEncoding.default, headers: headers).responseJSON { response in
print(response)
}
getContactsParameters() 控制台日志如下, 作为回应,我的成功代码为 Null。
我与后端人员交谈过,他们说,如果我没有收到此密钥“vUserList”,那么您可能会得到空响应。但是,我仔细检查了拼写和所有内容。 另一种情况是,他们说如果我们没有在正确的 json 中收到请求,那么您可能会得到空响应。
我尝试了许多不同的解决方案,但都没有奏效。 :(
任何帮助表示赞赏!
【问题讨论】:
-
你能显示你的
getContactsParameters()返回什么 -
也可以验证api使用的方法...是
.get还是.post? -
先用postman试试,看看得到的响应码。
-
我认为您需要传递联系人数组的 JSON 字符串。您能否与后端人员交叉验证所需的格式?
-
@iOSArchitect.com 用 getContactsParameters() 返回更新了我的答案