I'm new to Swift. I want to Authenticate a user. I'm using 'Deployd' as my server. This is what API's documentation says:
HTTP
To authenticate a user, send a POST request to /login with username and password properties in the request body.
POST /users/login
{ "username": "johnsmith", "password": "password" }
I'm using Alamofire to parse JSON data. Here is my code:
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)
}
This is the response from Xcode console:
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; } })
I know I'm doing it in total wrong manner.