URLConnection无法读取任何头字段但firefox确实如此

时间:2015-03-18 03:01:18

标签: java https urlconnection

我正在尝试使用java中的URLConnection从此URL获取头字段

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

但是我不能从这个链接获得任何字段,而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

enter image description here

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

1 个答案:

答案 0 :(得分:1)

在致电connect(), getInputStream()getResponseCode().

之前,没有任何标题字段