아하
생활
대담한황로142
대담한황로142
19.05.12

JSP GET 방식과POST 방식 차이가 궁금합니다.

안녕하세요 JSP 에서 GET 방식과POST 방식 개념이 조금 헷갈려서 질문 드립니다.

GET 방식이 파라미터가 노출되는 방식 인거죠?

55글자 더 채워주세요.
4개의 답변이 있어요!
  • 얄쌍한재규어4
    얄쌍한재규어4
    19.05.12

    - Get 방식 : URL에 피라미터 값을 보냅니다 URL에 클라이언트의 요청 파라미터가 다 보이는 것

    - Post 방식: Body에 내용을 숨겨 보내며, Get 방식 과는 달리 쿼리 글자 수 제약이 없으며 파일 업로드 등 가능 합니다.

  • 두 방식 모두, 서버에 요청을 하는 방법니다.

    • GET방식

    데이터를 URL뒤에 붙여서 보냅니다.

    만약 id와 password를 보낸다고 하면

    http://www.a-ha.io?id=me&password=12345

    와 같은 형태가 됩니다.

    URL 뒤에 "?" 마크는 통해 URL의 끝을 알리면서, 데이터 표현의 시작점을 의미합니다.

    데이터는 key 와 value 쌍으로 넣어야 합니다. 하나의 데이터가 끝나면 &로 마침을 알려줍니다.

    • POST 방식

    POST방식은 GET 방식과 달리, 데이터 전송을 기반으로 한 요청 메서드 입니다.

    GET방식은 URL에 데이터를 명시하여 보내지만, POST방식은 body에다가 데이터를 넣어서 보냅니다.

    따라서 body의 데이터를 설명하는 Content-Type이라는 헤더 필드가 들어가야 하고 어떤 데이터 타입인지 명시해야 합니다.

    Content-Type은 아래와 같이 다양한 종류가 있습니다.

    1) Multipart Related MIME 타입

    - Content-Type: Multipart/related

    - Content-Type: Application/X-FixedRecord

    2) XML Media의 타입

    - Content-Type: text/xml

    - Content-Type: Application/xml

    - Content-Type: Application/xml-external-parsed-entity

    - Content-Type: Application/xml-dtd

    - Content-Type: Application/mathtml+xml

    - Content-Type: Application/xslt+xml

    3) Application의 타입

    - Content-Type: Application/EDI-X12 <-- Defined in RFC 1767

    - Content-Type: Application/EDIFACT <-- Defined in RFC 1767

    - Content-Type: Application/javascript <-- Defined in RFC 4329

    - Content-Type: Application/octet-stream : <-- 디폴트 미디어 타입은 운영체제 종종 실행파일, 다운로드를 의미

    - Content-Type: Application/ogg <-- Defined in RFC 3534

    - Content-Type: Application/x-shockwave-flash <-- Adobe Flash files

    - Content-Type: Application/json <-- JavaScript Object Notation JSON; Defined in RFC 4627

    - Content-Type: Application/x-www-form-urlencode <-- HTML Form 형태

    * x-www-form-urlencode와 multipart/form-data은 둘다 폼 형태이지만 x-www-form-urlencode은 대용량 바이너리 테이터를 전송하기에 비능률적이기 때문에 대부분 첨부파일은 multipart/form-data를 사용하게 된다.

    4) 오디오 타입

    - Content-Type: audio/mpeg <-- MP3 or other MPEG audio

    - Content-Type: audio/x-ms-wma <-- Windows Media Audio;

    - Content-Type: audio/vnd.rn-realaudio <-- RealAudio; 등등

    5) Multipart 타입

    - Content-Type: multipart/mixed: MIME E-mail;

    - Content-Type: multipart/alternative: MIME E-mail;

    - Content-Type: multipart/related: MIME E-mail <-- Defined in RFC 2387 and used by MHTML(HTML mail)

    - Content-Type: multipart/formed-data <-- 파일 첨부

    6) TEXT 타입

    - Content-Type: text/css

    - Content-Type: text/html

    - Content-Type: text/javascript

    - Content-Type: text/plain

    - Content-Type: text/xml

  • 네 말씀하신거처럼 GET 방식은

    https://www.a-ha.io/questions/?name=aa&some=ss

    등 뒤에 파라미터가 보이는 방식이구요. 그래서 URL 주소만 복사하더라도 어느곳에서도 동일한 접근이 가능합니다.

    (캐시나 쿠키, 세션 등 추가적인 검증이 없다는 가정으로 )

    반대로 POST 방식은 URL 주소가 아닌곳에 파라미터가 들어가는 형식으로써 URL 주소를 알더라도 일반 방식으로는 접근이 불가합니다.

    똑같이 URL이 https://www.a-ha.io/questions 이더라도 post 방식으로 되어있는 페이지는 각자 다른 화면이 나오고

    URL 주소를 치고 들어가도 내가 원하는 페이지로 갈수 없는 구조라고 보시면 됩니다.

  • 댓글에 프알못님이 내용 적으신것데로

    JSP 가 아니라 HTTP에 대한 내용이구요

    GET 은 http://도메인주소/uid=test&pass=1234 이렇게 되는 주소가 GET 방식입니다

    POST 방식은 눈에 보이는 주소에는 http://도메인주소

    그리고 눈에 안보이는 HEADER 에는 data 스트림 형식으로 uid=test&pass=1234 이렇게 들어가게 됩니다

    그래서 보편적으로 보안상 로그인 방식을 POST방식으로 많이들 합니다