ABOUT ME

비바리퍼블리카(토스)에서 Frontend Developer로 일하고 있습니다.

  • [HTTP] HTTP Method 정리 / GET vs POST 차이점
    Computer Science 2019. 9. 10. 22:06

    이미지 출처: https://dev.to/williamragstad/how-to-use-ajax-3b5e

     

     

     

    GET이나 POST는 매우 자주 쓰는 HTTP 메소드들이다.

    아마 제일 많이 쓰지 않나 싶다. 

     

    근데 정확히 두 개가 어떻게 다른지,

    어떤 특징을 가지고 있는지 잘 모르겠어서 정리해보려고 한다.

    아래 글들은 영문 블로그 내용을 번역한 것이고 

    원문 글에 대한 출처는 글 하단에 있다.

     

     

     


     

    GET

    GET 메소드는 주로 데이터를 읽거나(Read) 검색(Retrieve)할 때에 사용되는 메소드이다. 만약에 GET요청이 성공적으로 이루어진다면 XML이나 JSON과 함께 200 (Ok) HTTP 응답 코드를 리턴한다. 에러가 발생하면 주로 404 (Not found) 에러나 400 (Bad request) 에러가 발생한다.

     

    HTTP 명세에 의하면 GET 요청은 오로지 데이터를 읽을 때만 사용되고 수정할 때는 사용하지 않는다. 따라서 이런 이유로 사용하면 안전하다고 간주된다. 즉, 데이터의 변형의 위험없이 사용할 수 있다는 뜻이다. 게다가 GET 요청은 idempotent하다. 즉, 같은 요청을 여러 번 하더라도 변함없이 항상 같은 응답을 받을 수 있다. 그러므로 GET을 데이터를 변경하는 등의 안전하지 않은 연산에 사용하면 안된다.

     

     

     

    POST

    POST 메소드는 주로 새로운 리소스를 생성(create)할 때 사용된다. 조금 더 구체적으로 POST는 하위 리소스(부모 리소스의 하위 리소스)들을 생성하는데 사용된다. 성공적으로 creation을 완료하면 201 (Created) HTTP 응답을 반환한다. POST 요청은 안전하지도 않고 idempotent하지도 않다. 다시 말해서 같은 POST 요청을 반복해서 했을 때 항상 같은 결과물이 나오는 것을 보장하지 않는다는 것이다. 그러므로 두 개의 같은 POST 요청을 보내면 같은 정보를 담은 두 개의 다른 resource를 반환할 가능성이 높다.

     

     

     

    GET vs POST

    HTTP POST 요청은 클라이언트에서 서버로 전송할 때 추가적인 데이터를 body에 포함할 수 있다. 반면에 GET 요청은 모든 필요한 데이터를 URL에 포함하여 요청한다. HTML의 <form>태그에 method="POST" 또는 method="GET"(기본값)을 모두 사용할 수 있다. 만약에 GET 메소드를 사용하면 모든 form data는 URL로 인코딩되어 action URL에 query string parameters로 전달된다. POST 메소드를 사용하면 form data는 HTTP request의 message body에 나타날 것이다.

     

     

     

      GET POST
    History

    Parameters remain in browser history because they are part of the URL.

    파라미터들은 URL의 일부분이기 때문에 브라우저 히스토리에 남는다.

     

    Parameters are not saved in browser history.

    파라미터들이 브라우저 히스토리에 저장되지 않는다.

    Bookmarked

    Can be bookmarked.

    요청 파라미터들이 URL로 인코딩되므로 즐겨찾기가 가능하다.

    Can not be bookmarked.

    요청 파라미터들이 request body에 포함되고 request URL에 나타나지 않으므로 즐겨찾기가 불가능하다.

    button/re-submit behaviour

    GET requests are re-executed but may not be re-submitted to server if the HTML is stored in the browser cache.

    GET 요청이 다시 실행되더라도 브라우저 캐시에 HTML이 저장되어있다면 서버에 다시 submit되지 않는다.

     

    The browser usually alerts the user that data will need to be re-submitted.

    브라우저가 보통 사용자에게 데이터가 다시 submit되어야 한다고 alert을 준다.

    Encoding type(enctype attribute) application/x-www-form-urlencoded multipart/form-data or application/x-www-form-urlencoded Use multipart encoding for binary data.
    Parameters

    can send but the parameter data is limited to what we can stuff into the request line (URL). Safest to use less than 2K of parameters, some servers handle up to 64K

    전송 가능하지만 URL에 넣을 수 있는 파라미터 데이터가 제한된다. 2K이하로 사용하는 것이 안전하며 몇몇 서버들은 64K까지 다룬다.

     

    Can send parameters, including uploading files, to the server.

    서버에 파일 업로드하는 것을 포함하여 파라미터를 전송할 수 있다.

    Hacked

    Easier to hack for script kiddies

    script kiddies에 의해 해킹되기 쉽다.

     

    More difficult to hack

    GET에 비해 좀 더 해킹하기 어렵다.

    Restrictions on form data type

    Yes, only ASCII characters allowed.

    오직 ASCII characters만 허용된다.

     

    No restrictions. Binary data is also allowed.

    제한이 없다. binary data도 허용된다.

    Security

    GET is less secure compared to POST because data sent is part of the URL. So it's saved in browser history and server logs in plaintext.

    GET은 POST에 비해 보안에 약하다. 그 이유는 데이터가 URL의 일부로 전송되고 그 때문에 브라우저 히스토리에 저장되며 서버가 플레인 텍스트로 로그를 남기기 때문이다.

     

    POST is a little safer than GET because the parameters are not stored in browser history or in web server logs.

    POST는 GET에 비해 보안에 조금 더 안전하다. 그 이유는 파라미터들이 브라우저 히스토리나 서버 로그에 저장되지 않기 때문이다.

    Restrictions on form data length

    Yes, since form data is in the URL and URL length is restricted. A safe URL length limit is often 2048 characters but varies by browser and web server.

    form data가 URL에 포함되고 URL 길이가 제한되기 때문에 form data의 길이도 제한된다. 안전한 URL 길이는 2048 characters이나 브라우저나 웹 서버에 따라 달라진다.

    No restrictions

    제한이 없다.

    Usability

    GET method should not be used when sending passwords or other sensitive information.

    GET 메소드는 비밀번호와 같은 민감한 정보들을 전송하는데 사용해선 안된다.

     

    POST method used when sending passwords or other sensitive information.

    POST 메소드는 비밀번호와 같은 민감한 정보를 전송하는데 사용된다.

    Visibility

    GET method is visible to everyone (it will be displayed in the browser's address bar) and has limits on the amount of information to send.

    GET 메소드는 모두에게 보여진다. (브라우저의 주소창에 그대로 보여지고 그에 따라 전송가능한 정보의 양도 제한된다.)

     

    POST method variables are not displayed in the URL.

    POST 메소드는 URL에 보여지지 않는다.

    Cached

    Can be cached

    GET은 idempotent하기 때문에 캐시가 된다.

    (같은 요청을 여러 번 보내도 항상 같은 응답이 온다.)

    Not cached

    POST는 idempotent하지 않기 때문에 캐시가 되지 않는다.

    (같은 요청을 여러 번 보내도 다른 응답이 올 수 있다.)

     

     

     

     

     


     

    참고자료:

    https://www.restapitutorial.com/lessons/httpmethods.html

     

    HTTP Methods for RESTful Services

    Below is a more-detailed discussion of the main HTTP methods. Click on a tab for more information about the desired HTTP method. The POST verb is most-often utilized to **create** new resources. In particular, it's used to create subordinate resources. Tha

    www.restapitutorial.com

    https://www.diffen.com/difference/GET-vs-POST-HTTP-Requests

     

    GET vs POST - Difference and Comparison | Diffen

    HTTP POST requests supply additional data from the client (browser) to the server in the message body. In contrast, GET requests include all required data in the URL. Forms in HTML can use either method by specifying method="POST" or method="GET" (default)

    www.diffen.com

    https://www.w3schools.com/tags/ref_httpmethods.asp

     

    HTTP Methods GET vs POST

    HTTP Request Methods The two most common HTTP methods are: GET and POST. What is HTTP? The Hypertext Transfer Protocol (HTTP) is designed to enable communications between clients and servers. HTTP works as a request-response protocol between a client and s

    www.w3schools.com

     

     

    반응형

    COMMENT