Question

I am writing a HTTP Webserver. My server has to handle Http multipart requests. In my previous implementation, I was extracting the data with the help of content length header present in every part of request. The client which I was using give content-length header with every part part(file) in the multipart request.

But another client is not giving content-length of each file. In my implementation I use content-length header to extract that much bytes and save them into a file.

Please tell me how can I extract data now.

The Headers which I am getting now are:

POST xxxxxxxxxxxxxxxxxxxxxxx&currentTab=PHOTOxxxxxxxxxxxxxxxx HTTP/1.1
Content-Length: 6829
Content-Type: multipart/form-data; boundary=SnlCg9JqTpQIl6t_mPzByTjZ8bD24kUj; charset=UTF-8
Host: host
Connection: Keep-Alive
User-Agent: Apache-HttpClient/xxxxxxxx
Accept-Encoding: gzip

--SnlCg9JqTpQIl6t_mPzByTjZ8bD24kUj
Content-Disposition: form-data; name="file"; filename="imagesCA5L2CL6_jpg(2)_jpg.jpg"
Content-Type: photo/jpg

**Some Data byte array**
--SnlCg9JqTpQIl6t_mPzByTjZ8bD24kUj--

In this request, there is now content-length header in part data.

EDIT:

Earlier this client used to send content-length header in every part. But for some reason it is not sending it any more. Can anybody suggest any reason for that.

thanks

No correct solution

OTHER TIPS

Like this : Reading file input from a multipart/form-data POST

Reading file input from a multipart/form-data POST

Take a look at RFC 2616 if you want to implement a HTTP/1.1 server. See section 4.4 on how to determine message length. See RFC 2388 on how to implement multipart/form-data.

The real answer is: don't reinvent the wheel, or you'll have to reimplmement a few hundred pages of RFC's. There are tons of libraries and servers out there.

If you do want to write your own web server, for example as an exercise, you would have found those RFC's already, right?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top