【问题标题】:ios - Swift JSON Post requestios - Swift JSON 发布请求
【发布时间】:2015-12-03 05:17:05
【问题描述】:

我是 swift 语言的新手。这是我的 JSON,需要发送到服务器以供用户登录

data={"email":"test@***.com","password":"mypassword","service":"login","deviceid":"sasa","devicetype":"android"}

我试过这些代码

    let params = [
            "data": [
                "email": username,
                "password": password,
                "service": "login",
                "deviceid": "sasa",
                "devicetype": "android"
            ]
        ]
Alamofire.request(.POST, "http://***.com/login", parameters: params, encoding: .JSON)
            .responseJSON {  response in
                print(response)
                        }

但是来自服务器的响应

SUCCESS: {
    service = login;
    status = failure;
    statusmessage = "Failure in post request , please check the key for form data";
}

【问题讨论】:

    标签: ios json swift post


    【解决方案1】:

    使用编码类型 URL 而不是 JSON:

    Alamofire.request(.POST, "http://***.com/login", parameters: params, encoding: .URL)
                .responseJSON {  response in
                    print(response)
                            }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-09-17
      • 2014-03-22
      • 2013-02-04
      • 2014-09-17
      • 2020-12-11
      • 1970-01-01
      • 2023-04-10
      相关资源
      最近更新 更多