使用alamofire发布form

编程入门 行业动态 更新时间:2024-10-13 20:17:02
本文介绍了使用alamofire发布form_data数据不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想从我的应用程序发送数据和图像,但不发送此代码

i want to send data and image from my apps but not send with this code

let parameters: [String: AnyObject] = [ "latitude" : lat as AnyObject, "longitude" : lng as AnyObject, "lokasi" : txtAlamat.text as AnyObject, "keterangan" : txtKeterangan.text as AnyObject, "jenis_absen" : absenIndex as AnyObject ] let requestUrl = "link.co/link_me" Alamofire.request(requestUrl, method: .post, parameters: parameters, encoding: JSONEncoding.default).authenticate(user: username!, password: password!).responseJSON { response in print(response) if let error = response.error{ self.hideLoading() _ = SweetAlert().showAlert("Warning", subTitle:error.localizedDescription, style: AlertStyle.error, buttonTitle:"Dismiss") return } debugPrint(response.result.value!) let parsedResult = JSON(response.result.value!)

邮递员成功发送带有form_data

in postman success send data with form_data

,我想添加图像,但我不知道

and i want to add image to, but i don't know how

此打印(参数)

this print(parameter)

推荐答案

如果您要发送参数和数据(例如例如),您必须使用上传请求(Alamofire.upload(...)),而不是常规请求。

If what you want is to send parameters and data (like an image for example), you MUST use an UPLOAD request (Alamofire.upload(...)), instead of the regular request.

上传请求使用NSData(字节)填充请求正文,因此您必须在 multipartFormData 正文中序列化参数和图像。

The Upload request uses NSData (bytes) to fill the request body, so you'll have to serialize the parameters and the image in the multipartFormData body.

我希望这对您有所帮助在这里澄清问题。

I hope this helped you a little bit, to clarify the problem here.

更多推荐

使用alamofire发布form

本文发布于:2023-11-26 08:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633387.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:alamofire   form

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!