在Alamofire中使用FORM DATA [英] Using FORM DATA with Alamofire

查看:378
本文介绍了在Alamofire中使用FORM DATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用alamofire一段时间了,但是我从未使用过表单数据Post。现在我被困住了。我有2个参数(电子邮件,密码),并且不知道如何将它们发布到服务器。谁能给我一个例子吗?

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?

推荐答案

所以我的解决方案是...。您必须指定参数在Alamofire中进行编码。因此代码将如下所示。

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

Swift 2.0

Swift 2.0

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

        // build parameters
        let parameters = ["email": "test@test.cz", "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)

            }
        }
    }

这篇关于在Alamofire中使用FORM DATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆