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;

        }

번호 제목 글쓴이 날짜 조회 수
246 이미지 파일의 화면사이즈와 포맷(확장자) 구하기 황제낙엽 2018.04.01 1004
245 File 을 다루기 위한 유틸 클래스 file 황제낙엽 2018.02.28 779
244 상수의 데이터 타입 황제낙엽 2018.01.26 828
243 Java에서 User-Agent 파써 사용하기 황제낙엽 2017.11.20 1104
242 현재 월,일,시간,분,초 등등 가져오기 황제낙엽 2017.11.02 1461
241 날짜, 시간 문자열 값으로 Date 오브젝트로 만들기 >> SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy", Locale.US) 황제낙엽 2017.10.31 2343
240 시스템 속성(System Property) 클래스를 이용하여 jni 라이브러리 사용하기 황제낙엽 2017.09.22 640
239 Java 실행 옵션들 황제낙엽 2017.08.23 3989
238 HttpsURLConnection 을 사용한 SSL서버 접속 file 황제낙엽 2017.08.02 958
237 서버구동시 주기적으로 동작을 수행하는 스레드를 함께 실행하는 서블릿 황제낙엽 2017.08.02 768
236 HttpURLConnection 사용 샘플( JSP , SERVLET ) 황제낙엽 2017.08.01 1118
235 HttpURLConnection 사용하기 황제낙엽 2017.08.01 1260
234 [HttpURLConnection] POST로 파라미터 넘기기 황제낙엽 2017.08.01 1260
233 HttpURLConnection POST 방식 사용하기 황제낙엽 2017.08.01 1233
232 Runtime 클래스를 이용한 윈도우 프로그램 실행 예제 황제낙엽 2017.08.01 833
231 자바 리플렉션(Java Reflection) 간단한 설명 및 사용방법 정리 file 황제낙엽 2017.07.10 647
230 Generate random numbers (Random.java) 황제낙엽 2017.07.02 1163
229 쓰레드(Thread)를 중간에 종료시키는 방법 황제낙엽 2017.03.15 5794
228 싱글톤 방식의 테스트용 Temporary Data Access Object 황제낙엽 2017.01.12 2191
227 SimpleDateFormat Symbol file 황제낙엽 2016.12.20 879