Привет, мне нужно оценить, поддерживает ли сервер сжатие gzip.Как отличить запрос и ответ от HTTPURLConnection?
Поэтому я хочу установить gzip как Accept-Encoding в свой запрос и оценить, содержит ли ответ сервера «Content-Encoding: gzip».
Однако я не совсем понимаю, как это сделать с помощью HTTPURLConnection. Особенно, когда запрашивать мой объект Connection об ответе. Я сейчас занимаюсь:
HttpURLConnection con = (HttpURLConnection) feedurl.openConnection();
con.setRequestProperty("Accept-Encoding", "gzip");
System.out.println("Current Accept-Encoding: "+con.getRequestProperty("Accept-Encoding"));
//check the response for the content-size
float feedsize = con.getContentLength()/1024f;
//the server uses transfer-encoding=chunked and does not specify
//a content length
if(con.getContentLength()==-1)
{
//count the content size manually
CountingInputStream counter = new CountingInputStream(con.getInputStream());
while(counter.read()!=-1)
{}
feedsize=counter.getCount()/1024f;
}
con.disconnect();
Uuuh! И даже с информацией об условном GET !!! Замечательно! Большое спасибо! – er4z0r