experts
I am trying to implement a downloader which handles HTTP protocol, I am able to send HTTP request using the following code:
StringBuilder request = new StringBuffer().append("GET ").append(uri.getPath());
if(uri.getQuery() != null)
request.append('?').append(uri.getQuery());
request.append(" HTTP/1.1\nHost: ").append(uri.getHost()).append("\nAccept: */*\n\n");
// send the request
outputStream.write(request.toString().getBytes("utf-8"));
outputStream.flush();
On receiving the response, I will need to save the body of the response to disk, and the job is done.
My question is: are there any HTTP headers that I can set for the request which will cause the server to send the response without HTTP headers(only the body)?
The reason why I am asking this question is that if that is possible, I don’t need to skip the HTTP headers manually when reading the response, I can directly start reading raw bytes from the input stream. all I want is the body of the response, the HTTP headers don’t matter much in this case.
No, you will always get the header back. And you will have to parse it since the resource you are trying to retrieve might come in different encodings and/or in multiple parts.
On the other hand, this has been done for you already by tools like
wget(1). You can either just use them, or look into the source to figure out what you need to do programmatically.