使用MultipartFormData发送参数的值错误

问题描述 投票:0回答:1

我所做的只是:

    func postMultipart(_ url: URL, parameters: [String: Any]?, headers: [String: String]?, image: UIImage?, success: @escaping SuccessHandler, failure: @escaping ErrorHandler) {
        manager.upload(multipartFormData: { multipart in
            if let image = image, let data = UIImagePNGRepresentation(image) {
                multipart.append(data, withName: "Passport", fileName: "picture.png", mimeType: "image/png")
            }
            if let parameters = parameters {
                for (key, value) in parameters {
                    multipart.append(self.archiver.data(from: value), withName: key)
                }
            }
        }, to: url, method: .post, headers: headers) { result in
            //parse result here
        }
    }

这是我看到的多部分发送到服务器的结果:

enter image description here

你可能会发现这是错的。它应该如下所示:

PMSReservationID: "23".

为什么它不是字符串,而是一些归档对象?

ios swift alamofire multipart
1个回答
0
投票

你可能需要它

for (key, value) in parameters {
   multipartFormData.append((value as AnyObject).data(using: String.Encoding.utf8.rawValue)!, withName: key)
}
© www.soinside.com 2019 - 2024. All rights reserved.