【问题标题】:Send data in HTTP Body with Alamofire使用 Alamofire 在 HTTP Body 中发送数据
【发布时间】:2016-03-08 10:05:53
【问题描述】:

我需要向我的应用程序的 API 发送登录请求,我没有编写 API 代码,有人正在为我们做这件事,所以我使用邮递员来测试请求并使用邮递员执行此操作:

URL : {{dev}}/customer/login-mock

Body / x-www-form-urlencoded : 

key = toto / value = toto
key = toto / value = toto

有了这个我得到了回应。

但我不知道如何用 Alamofire 实现它。我有点迷茫,我看到的所有教程都是使用 url 参数将参数发送到他们的 api。

我可以使用类似的函数:

RequestManager.request(.POST, "customer/login-mock", body: [username: "toto", password: "toto"])

class RequestManager: NSObject {
    request(method, url, body) {
      Alamofire.request(someRequest).responseJSON{response in ....}
    }

}

感谢您的帮助!

【问题讨论】:

    标签: ios swift alamofire


    【解决方案1】:

    使用这个:-

     Alamofire.request(.GET, query, parameters : param, headers : headers).responseJSON { (response) -> Void in
                    switch response.result
                    {
                    case .Success: //Success
                        if let value = response.result.value
                        {
                            completion(result: value, error: "")
                            print(value)
                        }
                    case .Failure(let error): //error
                        completion(result: "", error: error)
                    }
                }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-16
      • 2017-06-20
      • 1970-01-01
      • 2021-08-17
      • 1970-01-01
      相关资源
      最近更新 更多