从URL的http标头中获取Etag值

时间:2013-09-04 15:01:08

标签: java android apache http-headers httpclient

我似乎无法获得etag值。我按照教程:

http://www.mkyong.com/java/how-to-get-http-response-header-in-java/

我的代码:dr

public void getDatabaseEtag(){
        try {

            URL obj = new URL("url-here");
            URLConnection conn = obj.openConnection();
            Map<String, List<String>> map = conn.getHeaderFields();

            System.out.println("Printing Response Header...\n");

            for (Map.Entry<String, List<String>> entry : map.entrySet()) {
                System.out.println("Key : " + entry.getKey() 
                        + " ,Value : " + entry.getValue());
            }

            System.out.println("\nGet Response Header By Key ...\n");
            String server = conn.getHeaderField("ETag");

            if (server == null) {
                System.out.println("Key 'Etag' is not found!");
            } else {
                System.out.println("ETag - " + server);
            }

            System.out.println("\n Done");

        } catch (Exception e) {
            e.printStackTrace();
        }
    }

此代码无效。帮助!

修改 附加信息: 所以我的系统完全跳过etag并打印所有其他值。当我卷曲时 - 我会显示etag值!我可以补充一点,txt文件的url托管在dropbox上,如果这是相关的话。 dropbox是否故意不允许我的代码访问etag值?帮助!

修改

所以这是我从curl -i -v

获得的
* About to connect() to dl.dropboxusercontent.com port 443 (#0)
*   Trying 23.21.126.112...
* 0x8001f130 is at send pipe head!
* STATE: CONNECT => WAITCONNECT handle 0x800574c8; line 1032 (connection #0)
* Connected to dl.dropboxusercontent.com (23.21.126.112) port 443 (#0)
* successfully set certificate verify locations:
*   CAfile: /usr/ssl/certs/ca-bundle.crt
  CApath: none
* SSLv3, TLS handshake, Client hello (1):
* STATE: WAITCONNECT => PROTOCONNECT handle 0x800574c8; line 1145 (connection #0)
* SSLv3, TLS handshake, Server hello (2):
* SSLv3, TLS handshake, CERT (11):
* SSLv3, TLS handshake, Server key exchange (12):
* SSLv3, TLS handshake, Server finished (14):
* SSLv3, TLS handshake, Client key exchange (16):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSLv3, TLS change cipher, Client hello (1):
* SSLv3, TLS handshake, Finished (20):
* SSL connection using DHE-RSA-AES256-SHA
* Server certificate:
*        subject: C=US; ST=California; L=San Francisco; O=Dropbox, Inc; OU=Dropbox Ops; CN=*.dropboxusercontent.com
*        start date: 2013-03-05 00:00:00 GMT
*        expire date: 2014-03-12 12:00:00 GMT
*        subjectAltName: dl.dropboxusercontent.com matched
*        issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=DigiCert High Assurance CA-3
*        SSL certificate verify ok.
* STATE: PROTOCONNECT => DO handle 0x800574c8; line 1164 (connection #0)
> HEAD /s/w5hlozna36rlx5l/data.txt HTTP/1.1
> User-Agent: curl/7.29.0
> Host: dl.dropboxusercontent.com
> Accept: */*
>
* STATE: DO => DO_DONE handle 0x800574c8; line 1236 (connection #0)
* STATE: DO_DONE => WAITPERFORM handle 0x800574c8; line 1352 (connection #0)
* STATE: WAITPERFORM => PERFORM handle 0x800574c8; line 1363 (connection #0)
* HTTP 1.1 or later with persistent connection, pipelining supported
< HTTP/1.1 200 OK
HTTP/1.1 200 OK
< accept-ranges: bytes
accept-ranges: bytes
< cache-control: max-age=0
cache-control: max-age=0
< Content-length: 4206
Content-length: 4206
< Content-Type: text/plain; charset=ascii
Content-Type: text/plain; charset=ascii
< Date: Wed, 04 Sep 2013 15:31:42 GMT
Date: Wed, 04 Sep 2013 15:31:42 GMT
< etag: 3n
etag: 3n
< pragma: public
pragma: public
< Server: nginx
Server: nginx
< x-dropbox-request-id: a605f78c0ca6b0a97776cdb
x-dropbox-request-id: a605f70ec5c0ca6b0a97776cdb
< X-RequestId: 352c4a9a692dbbae66191266e22d
X-RequestId: 352c4adbbae66191266e22d
< x-server-response-time: 219
x-server-response-time: 219
< Connection: keep-alive
Connection: keep-alive

<
* STATE: PERFORM => DONE handle 0x800574c8; line 1533 (connection #0)
* Connection #0 to host dl.dropboxusercontent.com left intact

我不知道该如何处理这些信息以及如何从这些信息中查看我在Java中缺少的请求......需要帮助。

0 个答案:

没有答案