[英]Swift Alamofire using POST request
I am trying to a post request with a body in swift using Alamofire.我正在尝试使用 Alamofire 在 swift 中发布带有正文的请求。
How to pass below parameter:如何传递以下参数:
[ {"name":"online","value":false,"type":"checkbox"},{"name":"with_photo","value":true,"type":"checkbox"},{"name":"birthdate","value": {"lower":22,"upper":30}, "type":"range"} ] [ {"name":"online","value":false,"type":"checkbox"},{"name":"with_photo","value":true,"type":"checkbox"},{ “名称”:“生日”,“值”:{“下”:22,“上”:30},“类型”:“范围”}]
Anyone please help me.任何人请帮助我。
Thanks in advance提前致谢
Welcome to Stackoverflow!欢迎来到 Stackoverflow!
Going into the Alamofire documentation provide extensive detail into your problem with adding data to a post request.进入 Alamofire 文档提供了有关将数据添加到发布请求的问题的大量详细信息。 See here 看这里
To answer your question however, this code should do the trick.但是,要回答您的问题,此代码应该可以解决问题。
let parameters =[{"name":"online","value":false,"type":"checkbox"},{"name":"with_photo","value":true,"type":"checkbox"},{"name":"birthdate","value":{"lower":22,"upper":30},"type":"range"}]
// All three of these calls are equivalent
AF.request("https://httpbin.org/get", parameters: parameters) // encoding defaults to `URLEncoding.default`
AF.request("https://httpbin.org/get", parameters: parameters, encoder: URLEncodedFormParameterEncoder.default)
AF.request("https://httpbin.org/get", parameters: parameters, encoder: URLEncodedFormParameterEncoder(destination: .methodDependent))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.