Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/sharepoint/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 使用Alamofire获取空响应_Ios_Json_Swift_Alamofire - Fatal编程技术网

Ios 使用Alamofire获取空响应

Ios 使用Alamofire获取空响应,ios,json,swift,alamofire,Ios,Json,Swift,Alamofire,这是我需要发送到服务器的请求参数 { "vUserList": [ { "firstName": "Kate", "lastName": "Bell", "email": "katebell@mac.com" }, { "lastName": "Higgins", "firstName": "Daniel", "email": "dhiggins@mac.com" }, {

这是我需要发送到服务器的请求参数

{
  "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"
    }
  ]
}
getContactsParameters()控制台日志如下所示, 作为响应,我的成功代码为Null

我和后端人员谈过,他们说,如果我没有收到这个键“Vuser List”,那么您可能会得到空响应。但是,我仔细检查了拼写和所有内容。 另一种情况是,他们说,如果我们没有在正确的json中获取请求,那么您可能会得到空响应

我尝试了许多不同的解决方案,但没有一个奏效(

感谢您的帮助

这里我附上,邮递员截图。在邮递员它是工作良好。

检查邮递员后

请在您的请求中添加标题

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)
}
如果不行的话


URLEncoding()

请在您的请求中添加标题

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)
}
如果不行的话


URLEncoding()

let headers = [
    "Content-Type": "application/x-www-form-urlencoded"
]

希望它对您有用。

尝试将联系人数组的JSON字符串对象传递到API参数中

let headers = [
    "Content-Type": "application/x-www-form-urlencoded"
]

希望它对您有用。

您能展示一下您的
getContactsParameters()吗
returns所以你可以验证api使用的方法…是
.get
还是
.post
?先到邮递员那里试试,看看你得到的响应代码。我想你需要传递联系人数组的JSON字符串。你能不能与后端人员交叉验证所需的格式?@iOSArchitect.com用g更新了我的答案etContactsParameters()返回扫描您显示的
getContactsParameters()的内容
returns所以你可以验证api使用的方法…是
.get
还是
.post
?先到邮递员那里试试,看看你得到的响应代码。我想你需要传递联系人数组的JSON字符串。你能不能与后端人员交叉验证所需的格式?@iOSArchitect.com用g更新了我的答案etContactsParameters()返回我尝试了一个以上的值,并获得了此响应。成功:{DATA=”“;MESSAGE=“”;STATUS=1;}@iGatiShah您是否也添加了URLEncoding.httpBody?。因为我认为您不需要像接受回答中建议的那样手动解码是的,我也添加了!但是,它不起作用!我尝试了上面的一个,并得到了此响应。成功:{DATA=“”;MESSAGE=“”;STATUS=1;}@iGatiShah您也添加了URLEncoding.httpBody吗?因为我认为您不需要像接受回答中建议的那样手动解码是的,我也添加了这个!但是,它不起作用!