2015-03-18 1 views
0

Je suis en train d'obtenir les champs d'en-tête de cette URL à l'aide URLConnection en javaURLConnection ne peut pas lire tous les champs d'en-tête, mais Firefox ne

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 

Mais je ne peux pas obtenir tous les champs de ce lien alors que Firefox ont le conent -Longueur, 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

que puis-je faire dans ce cas, merci pour l'aide.

Répondre

1

Il n'y a pas de champs d'en-tête jusqu'à ce que vous appelez connect(),getInputStream() ou getResponseCode().

+0

Merci, je l'ai trouvé un tutoriel sur votre commentaire [doc] (http://docs.oracle.com/javase/tutorial/networking /urls/connecting.html) – thanh