HTTP POST 메서드
서버로 데이터를 전송한다. 요청 본문의 유형은 Content-Type 헤더로 나타낸다.
요청 내에서, 클라이언트는 서버에게 어떤 유형의 데이터가 실제로 전송됐는지를 알려준다.
PUT과 POST의 차이는 멱등성으로, PUT은 멱등성을 가진다. PUT은 한 번을 보내도, 여러 번을 연속으로 보내도 같은 효과를 보인다. 즉, 부수 효과(side effect)가 없다.
POST 요청은 보통 HTML 양식을 통해 서버에 전송하며, 서버에 변경사항을 만든다. 이 경우의 콘텐츠 유형(Content-Type)은 *<form> 요소의 enctype 특성이나 <input>, <button> *요소의 formenctype 특성 안에 적당한 문자열을 넣어 결정한다.
- application/x-www-form-urlencoded: &으로 분리되고, "=" 기호로 값과 키를 연결하는 key-value tuple로 인코딩되는 값이다. 영어 알파벳이 아닌 문자들은 percent encoded 으로 인코딩된다. 따라서, 이 content type은 바이너리 데이터에 사용하기에는 적절치 않다. (바이너리 데이터에는 use multipart/form-data 를 사용)
-Content-Type
응답 내에 있는 Content-Type 헤더는 클라이언트에게 반환된 컨텐츠의 컨텐츠 유형이 실제로 무엇인지를 알려준다.
HTML 폼 전송으로 일어나는 POST 요청 내에서, 요청의 Content-Type은 <form> 요소 상의 enctype 속성에 의해 지정된다.
<form action="/" method="post" enctype="multipart/form-data">
<input type="text" name="description" value="some text">
<input type="file" name="myFile">
<button type="submit">Submit</button>
</form>
요청은 다음과 같다.
POST /foo HTTP/1.1
Content-Length: 68137
Content-Type: multipart/form-data; boundary=---------------------------974767299852498929531610575
Content-Disposition: form-data; name="description"
---------------------------974767299852498929531610575
some text
---------------------------974767299852498929531610575
Content-Disposition: form-data; name="myFile"; filename="foo.txt"
Content-Type: text/plain
(content of the uploaded file foo.txt)
---------------------------974767299852498929531610575--