What is the proper API calling Syntax from Alamofire?

99封情书 提交于 2019-12-25 06:04:04

问题


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.

来源:https://stackoverflow.com/questions/30508534/what-is-the-proper-api-calling-syntax-from-alamofire

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!