Alamofire request missing "Content-length"

The request that I get on the server side is missing content-lengtheach multipart.

I tried changing the headers, but it still won’t display.

I successfully send the image file and some data from the device / simulator to the server using Alamofire / multipart form-data strong>.

 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)
        }
    })

Update: Even after saving, headers: nilit will not be displayed.

Retrieved from alamofire: -

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

123456
--alamofire.boundary.cc9684e085522290

How to get the length of the content for each transmitted data set?

+5
source share
1 answer

headers: ["Content-Length"]

+2

All Articles