gpt4 book ai didi

swift - Alamofire 请求丢失 "Content-length"

转载 作者:搜寻专家 更新时间:2023-10-31 08:03:52 26 4
gpt4 key购买 nike

我在服务器端收到的请求缺少每个多部分的 content-length

我尝试更改标题,但它仍然不显示。

我使用 Alamofire/multipart form-data 成功地将图像文件和一些数据从设备/模拟器发送到服务器。

 var parameters = […]

let url = try! URLRequest(url: “URL”, method: .post, headers: ["Content-type": "multipart/form-data"])

Alamofire.upload(multipartFormData: { (multipartFormData) in
for (key, value) in parameters {
multipartFormData.append((value.data(using: String.Encoding.utf8)!), withName:key)

}
multipartFormData.append(UIImageJPEGRepresentation(image!, 0.5)!, withName: “Image”, mimeType: "image/jpeg")

}, to: "\(url)" , encodingCompletion: {(encodingResult) in

switch encodingResult {
case .success(let upload, _, _):
//print(result)
upload.uploadProgress(closure: { (Progress) in

self.progressView.progress = Float(Progress.fractionCompleted)
print("Upload Progress: \(Progress.fractionCompleted)")
})


print("REQUEST = \(request)")
print(encodingResult)

upload.responseJSON { response in

//self.delegate?.showSuccessAlert()
print( response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialisation
// self.showSuccesAlert()
//self.removeImage("frame", fileExtension: "txt")
if let JSON = response.result.value {
print("JSON: \(JSON)")
}
}

case .failure(let encodingError):
//self.delegate?.showFailAlert()
print(encodingError)
}
})

更新:即使在保留 headers: nil 之后,它也不会显示。

从 alamofire 收到:-

--alamofire.boundary.cc9684e085522290
Content-Disposition: form-data; xyz="abc"

123456
--alamofire.boundary.cc9684e085522290

如何获取传递的每个多部分数据的内容长度?

最佳答案

尝试将标题更改为

标题:["Content-Length"]

关于swift - Alamofire 请求丢失 "Content-length",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48581254/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com