我想从我的应用程序发送数据和图像,但不发送此代码
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
发布评论