我目前正在使用 alamofire 从网络服务请求数据。一切正常,但我对如何使用 get 方法将数据上传到我的服务器有疑问。
Web 服务示例 --> http://www.google.com/id=2&name=trump&message=fakenews
我尝试使用传统的 alamofire.request("weberservice") 但它不起作用。
如何使用 alamofire 发送此信息?
最佳答案
您想要做的是发出 POST
请求。这会将数据发送到服务器。
您要做的是使用 request
方法,但为 HTTP 方法添加一个附加参数:
Alamofire.request("<YOUR-URL>", method: .post)
Alamofire 文档 here讨论当您发出 POST
请求时将数据传递到服务器。您基本上使用字典添加第三个参数:
let parameters: Parameters = ["foo": "bar"]
// All three of these calls are equivalent
Alamofire.request("https://httpbin.org/get", parameters: parameters)
// https://httpbin.org/get?foo=bar
来自 Alamofire 文档
关于Swift 3 使用 Alamofire 将数据上传到服务器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43946570/