Using FORM DATA with Alamofire

Pan Mluvčí picture Pan Mluvčí · Nov 23, 2015 · Viewed 16.1k times · Source

I am using alamofire for some time now, but I have never used a form data Post. Now I am stuck. I have 2 params (email, password) and don't know how POST them to server. Can anyone give me an example please?

Answer

Ahmad Ismail picture Ahmad Ismail · Dec 8, 2016

And here is a sample code for Alamofire 4.0 in Swift 3.0

    let url = "http://testurl.com"

    let parameters = [
        "email": "[email protected]",
        "password": "55555"
    ]


    Alamofire.request(url, method: .post, parameters: parameters, encoding: URLEncoding.default).responseJSON { response in
        switch response.result {
        case .success:
            if let value = response.result.value {
                print(value)
            }
        case .failure(let error):
            print(error)
        }
    }