How do I differentiate between request and response in an HTTPURLConnection?

Hi I need to evaluate if a server supports gzip compression. Therefore I want to set gzip as Accept-Encoding in my request and evaluate if the response of the server containts "Content-Encoding: gzip". However I am not quite clear on how to do this with HTTPURLConnection. Especially when to query my Connection object about the response. I currently do: 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(!=-1) {} feedsize=counter.getCount()/1024f; } con.disconnect();

以上就是How do I differentiate between request and response in an HTTPURLConnection?的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准