Java – HTTP get: Download header files only? (not supported by head)
•
Java
In my code, I use some HTTP get requests to download some files as streams I use the following code:
public String getClassName(String url) throws ClientProtocolException,IOException { HttpResponse response = sendGetRequestJsonText(url); Header[] all = response.getAllHeaders(); for (Header h : all) { System.out.println(h.getName() + ": " + h.getValue()); } Header[] headers = response.getHeaders("Content-Disposition"); InputStreamParser.convertStreamToString(response.getEntity().getContent()); String result = ""; for (Header header : headers) { result = header.getValue(); } return result.substring(result.indexOf("''") + "''".length(),result.length()).trim(); }
However, this will download the entire content of the response I want to retrieve only HTTP headers without content The head request doesn't seem to work because I get state 501 and it's not implemented How can I do this?
Solution
You can consider making only one head request instead of making a get request:
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码