Bonjour,

Je rencontre un petit souci concernant un retour de flux qui devrait être compressé mais qui apparemment ne l’est pas.

J’ai bien renseigné le header "Accept-Encoding:"gzip", mais il n’a pas grand efficacité dans la mesure où une exception est levée : "java.util.zip.ZipException: Not in GZIP format "

Et cela fonctionne normalement si je retire :"new GzipDecompressingEntity(...)

Je n’arrive pas à voir ou cela peut bloquer ou si l‘approche n‘est pas correcte.


Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
public class showResponseHeader {
 
	public void connect() throws ClientProtocolException, IOException {
		BasicCookieStore cookieStore = new BasicCookieStore();		
		CloseableHttpClient httpclient = HttpClients.createDefault();
		HttpGet httpGet = new HttpGet("http://www.site.fr");
		httpGet.addHeader("Accept-Encoding", "gzip");
		httpGet.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
		httpGet.addHeader("Accept-Language", "fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4");
		httpGet.addHeader("Host", "www.site.fr");
		httpGet.addHeader("Connection", "keep-alive");
		httpGet.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 6.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.57 Safari/537.36");		
		CloseableHttpResponse response = httpclient.execute(httpGet);
		HttpEntity entity = new GzipDecompressingEntity(response.getEntity());
		InputStream instream = entity.getContent();
		BufferedReader reader = new BufferedReader(new InputStreamReader(instream));
		String inputLine;
		while ((inputLine = reader.readLine()) != null) {
			System.out.println(inputLine);
		}
		reader.close();
		instream.close();
		response.close();
	}
}