From 218934fa2ed1c702a6d3923d2aa2cc6b43c48684 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:43:23 -0500 Subject: initial commit --- files/zh-tw/web/http/methods/post/index.html | 124 +++++++++++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 files/zh-tw/web/http/methods/post/index.html (limited to 'files/zh-tw/web/http/methods/post') diff --git a/files/zh-tw/web/http/methods/post/index.html b/files/zh-tw/web/http/methods/post/index.html new file mode 100644 index 0000000000..3332297535 --- /dev/null +++ b/files/zh-tw/web/http/methods/post/index.html @@ -0,0 +1,124 @@ +--- +title: POST +slug: Web/HTTP/Methods/POST +translation_of: Web/HTTP/Methods/POST +--- +
{{HTTPSidebar}}
+ +

The HTTP POST method sends data to the server. The type of the body of the request is indicated by the {{HTTPHeader("Content-Type")}} header.

+ +

The difference between PUT and {{HTTPMethod("POST")}} is that PUT is idempotent: calling it once or several times successively has the same effect (that is no side effect), where successive identical POST may have additional effects, like passing an order several times.

+ +

A POST request is typically sent via an HTML form and results in a change on the server. In this case, the content type is selected by putting the adequate string in the {{htmlattrxref("enctype", "form")}} attribute of the {{HTMLElement("form")}} element or the {{htmlattrxref("formenctype", "input")}} attribute of the {{HTMLElement("input") }} or {{HTMLElement("button")}} elements:

+ + + +

When the POST request is sent via a method other than an HTML form — like via an {{domxref("XMLHttpRequest")}} — the body can take any type. As described in the HTTP 1.1 specification, POST is designed to allow a uniform method to cover the following functions:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Request has bodyYes
Successful response has bodyYes
{{Glossary("Safe")}}No
{{Glossary("Idempotent")}}No
{{Glossary("Cacheable")}}Only if freshness information is included
Allowed in HTML formsYes
+ +

格式

+ +
POST /test
+
+ +

範例

+ +

使用 application/x-www-form-urlencoded 內容類型的簡易表單:

+ +
POST /test HTTP/1.1
+Host: foo.example
+Content-Type: application/x-www-form-urlencoded
+Content-Length: 27
+
+field1=value1&field2=value2
+ +

使用 multipart/form-data 內容類型的表單:

+ +
POST /test HTTP/1.1
+Host: foo.example
+Content-Type: multipart/form-data;boundary="boundary"
+
+--boundary
+Content-Disposition: form-data; name="field1"
+
+value1
+--boundary
+Content-Disposition: form-data; name="field2"; filename="example.txt"
+
+value2
+--boundary--
+
+ +

規範

+ + + + + + + + + + + + + + + + + + +
規範標題
{{RFC("7231", "POST", "4.3.3")}}Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content
{{RFC("2046", "Common Syntax", "5.1.1")}}Multipurpose Internet Mail Extensions (MIME) Part Two: Media Types
+ +

瀏覽器相容性

+ + + +

{{Compat("http.methods.POST")}}

+ +

參見

+ + -- cgit v1.2.3-54-g00ecf