Using FORM DATA with Alamofire

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)
        }
    }

Swift 5

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

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


AF.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)
    }
}

So my solution is.... you have to specify the Parameter Encoding in Alamofire. So the code will look like this.

Swift 2.0

func registerNewUserFormData(completionHandler: (Bool, String?) -> ()){

        // build parameters
        let parameters = ["email": "[email protected]", "password": "123456"]

        // build request
        Alamofire.request(.POST, urlDomain + "register", parameters: parameters, encoding: .URL).responseJSON { response in

            switch response.result {
            case .Success:
                print("Validation Successful")
                if let JSON = response.result.value {
                    print(JSON)
                }

            case .Failure(let error):
                print(error)

            }
        }
    }