ios - Swift JSON Post 请求

标签 ios json swift post

我是 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";
}

最佳答案

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

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

关于ios - Swift JSON Post 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34058383/

相关文章:

ios - 如何将事件发送到我的(子)UIView?

ios - Swift xcode 两个错误 : Cannot assign value of type 'ShapeType' to type "ShapeButton.ShapeType"

ios - 如果我执行 unwind segue (show),母 View Controller 如何获取 subview Controller ?

ios - 如何获得适合整个屏幕的图像?

ios - Mail iOS应用程序如何在未运行时提醒新邮件

ios - 基于另一个属性的地幔属性类?

ios - - iOS : Make a tree based on a JSON

PHP 和 JSON 按用户显示列数据

javascript - 具有相同名称参数的表单的 JSON Stringify

mysql - 在 Node 中从文件与数据库中提供内容