English 中文(简体)
HTTP 选择: 只有下载头盔? (HEAD没有得到支持)
原标题:HTTP Get: Only download the header? (HEAD is not supported)

In my code I use some Http Get request to download some files as a stream. 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();
    }

但这下载了答复的全部内容。 我只想找不到内容的负责人。 “欧洲复兴开发银行”的请求似乎不可行,因为当时我获得的地位为501,但没有得到执行。 我如何能够这样做?

最佳回答

您可以不提出GET的要求,而只考虑提出HEAD。 请求:

The HEAD method is identical to GET except that the server MUST NOT return a message-body in the response. The metainformation contained in the HTTP headers in response to a HEAD request SHOULD be identical to the information sent in response to a GET request. This method can be used for obtaining metainformation about the entity implied by the request without transferring the entity-body itself. This method is often used for testing hypertext links for validity, accessibility, and recent modification.

问题回答

You might be able to use the Range header in your request to specify a range of bytes to include in the response entity. Possibly something like:

Range: bytes=0-0

如果其工作,请在回复实体中填写<代码>Range的标书。 然而,我没有尝试过这一点,也没有工作

服务器MAY无视地圈头。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...