1
I’m making a call POST
with Swift using the Alamofire library. The service call works, but I need to check the email and the password user-typed.
How do I pass the variables email
and senha
in the parameters
of the JSON?
Thanks in advance. Follow the part of my code that I am in need of help:
let URL = NSURL(string: "http://jsonplaceholder.typicode.com/posts")!
let mutableURLRequest = NSMutableURLRequest(URL: URL)
mutableURLRequest.HTTPMethod = "POST"
let parameters = ["title": "Frist Psot", "body": "I iz fisrt", "userId": 1]
do {
mutableURLRequest.HTTPBody = try NSJSONSerialization.dataWithJSONObject(parameters, options: NSJSONWritingOptions())
} catch{
}
mutableURLRequest.setValue("application/json", forHTTPHeaderField: "Content-Type")
Alamofire.request(mutableURLRequest)
.responseJSON { response in
print(response.response) // URL response
print(response.result)
if let JSON = response.result.value {
print("JSON: \(JSON)")
let usuario = JSON.objectForKey("data");
print(usuario)
//String nome = JSON.objectForKey("nome") == nil ? "" :JSON.objectForKey("nome") as! String;
}
}
Thank you very much :)
– Alice Kellen