URLConnection 无法读取任何 header 字段,但 firefox 可以

URLConnection cannot read any header fields but firefox does

我正在尝试使用 java

中的 URLConnection 从此 url 获取 header 字段
https://farm9.staticflickr.com/8709/16206420933_5d7427b8e3_o_d.jpg 

URL fUrl = new URL(url);
                URLConnection connection = fUrl.openConnection();
                for (Map.Entry<String, List<String>> k : connection.getHeaderFields().entrySet()) {
                    System.out.println(k.toString());
                }//Return nothing

但是我无法从此 link 获取任何字段,而 firefox 有 conent-length、accept-ranges ...

HTTP/1.1 200 OK

Date: Wed, 18 Mar 2015 02:44:58 GMT

Content-Type: image/jpeg

Content-Length: 11734133

p3p: policyref="http://info.yahoo.com/w3c/p3p.xml", CP="CAO DSP COR CUR ADM DEV TAI PSA PSD IVAi IVDi CONi TELo OTPi OUR DELi SAMi OTRi UNRi PUBi IND PHY ONL UNI PUR FIN COM NAV INT DEM CNT STA POL HEA PRE LOC GOV"

x-photo-origin: gq1

Content-Disposition: attachment; filename=16206420933_5d7427b8e3_o.jpg

Pragma: no-cache

Expires: 0

Last-Modified: Sun, 15 Mar 2015 20:53:26 GMT

Accept-Ranges: bytes

Age: 0

Via: http/1.1 photocache907.flickr.gq1.yahoo.com (ApacheTrafficServer [cMsSf ]), http/1.1 cache127.flickr.sg3.yahoo.com (ApacheTrafficServer [cMsSf ])

Server: ATS

ytracetag: 000100080000000100000000000000003e5ac2bfd747bd07000000000000000013cc77a17690ed0013cc77a183c7b900592ecf220000000022cf2e594d34a5ef

X-Firefox-Spdy: 3.1

那么在这种情况下我能做什么,谢谢你的帮助。

在您调用 connect(), getInputStream()getResponseCode().

之前,没有任何 header 字段