HTTP GET:只有下载的头? (不支持HEAD) [英] HTTP Get: Only download the header? (HEAD is not supported)

查看:214
本文介绍了HTTP GET:只有下载的头? (不支持HEAD)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的code我使用一些HTTP GET请求下载一些文件作为一个流。我用下面的code:

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();
    }

但这种下载响应的全部内容。我想不只是内容的检索HTTP标头。 HEAD请求似乎没有工作,因为当时我拿到的状态501,不落实。我该怎么做?

But this downloads the full content of the response. I want to retrieve only the http headers without the content. A HEAD request seems not to work because then i get the status 501, not implemented. How can I do that?

推荐答案

,你可能会考虑的仅仅是的 HEAD请求

Instead of making a GET request, you might consider just making a HEAD request:

HEAD方法是相同的除了GET,该服务器不能
  在响应返回消息体。该载元信息
  在HTTP头响应HEAD请求应该是相同的
  响应于GET请求发送的信息。这种方法可以
  用于获取有关隐含的实体元信息
  要求不转移对实体本身。此方法是
  通常用于有效性,可访问性测试超文本链接,
  和最近的修改。

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.

这篇关于HTTP GET:只有下载的头? (不支持HEAD)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆