I'm new to the ranch but I'm hoping you guys can help me out with a small I/O problem.
I'm trying to learn a bit more about HTTP protocol, so I wrote some Java code to send & receive text HTTP messages over Sockets.
For example, I might send: "GET /somepath/somefile.html HTTP/1.0\r\n\r\n", and listen for a response from the web server.
However, I run into problems when I request a non-text file (like an Image), I can't figure out how to process it. A website I'm reading states:
If its not text, how do I process the body? Do I just read raw bytes from the InputStream?How can I tell where the 'Header Line' ends & the 'Message Body' starts? Do I simply check for "\r\n\r\n"?How do I determine the byte length of the content? Can I trust the "Content-Length" field? or Do I loop until EOF?
An HTTP message may have a body of data sent after the header lines. In a response, this is where the requested resource is returned to the client (the most common use of the message body)
I can't get my program to work with non text-files. I tried reading the HTTP RFC, but it didn't help much.