我是 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/