【发布时间】:2015-10-29 16:05:05
【问题描述】:
我是 Swift 新手。我想对用户进行身份验证。我正在使用“已部署”作为我的服务器。 API 的文档是这样说的:
HTTP
要对用户进行身份验证,请使用用户名向 /login 发送 POST 请求 和请求正文中的密码属性。
POST /users/login
{ "用户名": "johnsmith", "密码": "密码" }
我正在使用 Alamofire 解析 JSON 数据。这是我的代码:
let user = "root"
let password = "root"
// this is a testing user i've created in deployd's dashboard.
let credential = NSURLCredential(user: user, password: password, persistence: .ForSession)
Alamofire.request(.POST, "http://localhost:2406/users/login/\(user)/\(password)")
.authenticate(usingCredential: credential)
.response { request, response, _, error in
println(response)
}
这是来自 Xcode 控制台的响应:
Optional(<NSHTTPURLResponse: 0x7fdd906dc3a0> { URL: http://localhost:2406/users/login/root/root } { status code: 400, headers {
Connection = "keep-alive";
"Content-Type" = "application/json";
Date = "Thu, 06 Aug 2015 13:01:54 GMT";
"Transfer-Encoding" = Identity; } })
我知道我这样做的方式完全错误。
【问题讨论】:
标签: ios swift alamofire deployd