sitelink1 https://developer.mozilla.org/en-US/docs...t-Encoding 
sitelink2 http://mikelim.mintocean.com/8 
sitelink3  
sitelink4  
sitelink5  
sitelink6  

HTTP 연결시 Request header에 Accept-Encoding = gzip 또는 deflate 로 지정이 되었을 경우(Accept-Encoding="gzip, deflate")

서버에서는 트래픽 양을 줄이기 위하여 컨텐츠를 모두 압축하여 보내준다.

물론 서버 설정에서 gzip으르 지원하지 않도록 설정을 바꿀 수 있지만 그렇게 되면 트래픽이 과도하게 발생된다.

어쨌건간에 Http로 연결을 한 후 gzip으로 인코딩이 되었다면 Java에서 GZIPInputStream 으로 간단히 해결 할 수 있다.

 

 

 

 

        URL url = new URL("http://[도메인]/[서비스경로]");

        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        connection.setDoInput(true);

        

        connection.setRequestProperty("Host", "tops.tobesoft.com");

        connection.setRequestProperty("X-Requested-With", "XMLHttpRequest");

        connection.setRequestProperty("Referer", "http://[도메인]/[서비스경로]/[서비스페이지]");

        connection.setRequestProperty("Accept", "application/xml, text/xml, */*");

        connection.setRequestProperty("Accept-Encoding", "gzip, deflate"); //이 코드가 들어가면 서버는 응답데이터를 압축해서 보내준다

        connection.setRequestProperty("Content-type", "text/xml;charset=UTF-8");

        connection.setRequestProperty("Pragma", "no-cache");

        connection.setRequestMethod("POST");

        connection.setDoOutput(true);

 

        OutputStream out_stream = connection.getOutputStream();

        out_stream.write( trData.getBytes("UTF-8") );

        out_stream.flush();

        out_stream.close();

        

        connection.connect();

        

        String sessCookie = connection.getHeaderField("Set-Cookie");

        if (sessCookie != null) {

            System.out.println("쿠키:"+sessCookie);

        }

        

        BufferedReader brin = null;

        String cEncode = connection.getHeaderField("Content-Encoding");

        if (cEncode != null &&

                (cEncode.toLowerCase().indexOf("gzip") > -1 

                || cEncode.toLowerCase().indexOf("deflate") > -1

                || cEncode.toLowerCase().indexOf("compress") > -1)) {

            brin = new BufferedReader(new InputStreamReader(new GZIPInputStream(connection.getInputStream())));

        } else {

            brin = new BufferedReader(new InputStreamReader(connection.getInputStream(), "UTF-8"));

        }

        

        String resStr = null;

        StringBuffer resStrBuff = new StringBuffer();

        try {

            while ((resStr = brin.readLine()) != null) {

                resStrBuff.append(resStr);

            }

        } finally {

            if (brin != null) {

                brin.close();

                brin = null;

            }

            connection = null;

            url = null;

            resStr = null;

        }

번호 제목 글쓴이 날짜 조회 수
266 한글 인코딩의 이해 2편: 유니코드와 Java를 이용한 한글 처리 file 황제낙엽 2019.05.07 1076
265 응답 헤더의 Content-disposition 속성 황제낙엽 2019.04.16 1255
264 StringUtils - 문자열 처리 유틸리티 file 황제낙엽 2019.04.15 880
263 File.length() 에 대하여 황제낙엽 2019.03.24 1137
262 File.delete() 와 File.deleteOnExit() 황제낙엽 2019.03.24 3380
261 List to Array / Array to List 황제낙엽 2019.03.24 794
260 Oracle JAVA 유료화에 관련한 최신 기사 황제낙엽 2019.01.23 923
259 Iterator.next() - NoSuchElementException 황제낙엽 2018.10.28 999
258 OracleJDK 유료화 FAQ (Oracle Java 의 유료화에 대한 어느분의 정리) 황제낙엽 2018.10.11 851
257 메일서버(daum.net)에 POP3를 이용하여 메일 가져오기 예제 file 황제낙엽 2018.10.09 2000
256 Sending mail through Java using SMTP of gmail file 황제낙엽 2018.09.13 1355
255 Read or get mails using pop in java (using gmail) file 황제낙엽 2018.09.13 12215
254 Collections.sort() , Comparator 황제낙엽 2018.08.23 947
253 JavaMail - Connecting Gmail pop3 server. 황제낙엽 2018.08.20 1784
252 JavaMail - 네이버 메일 수신하기(POP3) 황제낙엽 2018.08.20 1934
251 JavaMail - POP3로 메일 읽어오기 - 단순샘플 황제낙엽 2018.08.20 991
» [HttpURLConnection, HttpsURLConnection] Response 로 받은 데이터가 압축되어 있는 경우(gzip, deflate) 황제낙엽 2018.08.16 1115
249 [HttpURLConnection, HttpsURLConnection] 자바 Http / https 의 결과를 주고받을때 세션을 유지 황제낙엽 2018.08.12 1049
248 [HttpURLConnection] 자바(Java) URL 접속 및 세션 관리 file 황제낙엽 2018.08.12 1034
247 org.apache.commons.io.FilenameUtils (getExtension) 황제낙엽 2018.04.01 2106