gpt4 book ai didi

java - URLConnection 无法读取任何 header 字段,但 Firefox 可以

转载 作者:行者123 更新时间:2023-12-01 11:46:06 25 4
gpt4 key购买 nike

我正在尝试使用 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

但是我无法从此链接获取任何字段,而 Firefox 有内容长度、接受范围...

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

那么在这种情况下我该怎么办,谢谢您的帮助。

最佳答案

在调用 connect()、 getInputStream()getResponseCode() 之前,不会有任何 header 字段。

关于java - URLConnection 无法读取任何 header 字段,但 Firefox 可以,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29113419/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com