I am trying to call following API:
http -v -a qi.test.ac@gmail.com:pasword -f POST 'http://localhost:8080/api/v1/user/messages' from="qi.test.ac@gmail.com" to={"qi.test.ac@gmail.com","qi_test_ac@yahoo.com"} subject="test_sub" bodyText="testing hello"
I successfully called it from terminal using HTTPie using normally above command.
Now I want to call it from Alamofire. I have tried in following way:
parameters = [
"from" : fromMail,
"to" : ["qi.test.ac@gmail.com","qi_test_ac@yahoo.com"]
]
parameters["subject"] = message.getSubject()
parameters["bodyText"] = message.getBodyText()
Alamofire.request(.POST, urlString, parameters: parameters)//, encoding: .JSON)
.authenticate(user: userName, password: password)
.validate(statusCode: 200..<201)
.validate(contentType: ["application/json"])
.responseJSON {
(_, _, jsonData, error) in
if(error != nil) {
println("\n sendMessage attempt json response:")
println(error!)
delegate?.messageSent?(false)
return
}
println("Server response during message sending:\n")
let swiftyJSONData = JSON(jsonData!)
println(swiftyJSONData)
delegate?.messageSent?(true)
}
I have tried by url encoding which is by default and also in json encoding. But not succeeded yet. Any idea?
Thanks in advance.