aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/http/methods/post
diff options
context:
space:
mode:
authorPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
committerPeter Bengtsson <mail@peterbe.com>2020-12-08 14:40:17 -0500
commit33058f2b292b3a581333bdfb21b8f671898c5060 (patch)
tree51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/web/http/methods/post
parent8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff)
downloadtranslated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2
translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip
initial commit
Diffstat (limited to 'files/zh-cn/web/http/methods/post')
-rw-r--r--files/zh-cn/web/http/methods/post/index.html120
1 files changed, 120 insertions, 0 deletions
diff --git a/files/zh-cn/web/http/methods/post/index.html b/files/zh-cn/web/http/methods/post/index.html
new file mode 100644
index 0000000000..7521f6b0ee
--- /dev/null
+++ b/files/zh-cn/web/http/methods/post/index.html
@@ -0,0 +1,120 @@
+---
+title: POST
+slug: Web/HTTP/Methods/POST
+tags:
+ - HTTP
+ - 参考
+ - 请求方法
+translation_of: Web/HTTP/Methods/POST
+---
+<div>{{HTTPSidebar}}</div>
+
+<p><strong>HTTP <code>POST</code> 方法</strong> 发送数据给服务器. 请求主体的类型由 {{HTTPHeader("Content-Type")}} 首部指定.</p>
+
+<p>PUT 和{{HTTPMethod("POST")}}方法的区别是,PUT方法是幂等的:连续调用一次或者多次的效果相同(无副作用)。连续调用同一个POST可能会带来额外的影响,比如多次提交订单。</p>
+
+<p>一个 <code>POST</code> 请求通常是通过 <a href="/en-US/docs/Web/Guide/HTML/Forms">HTML 表单</a>发送, 并返回服务器的修改结果. 在这种情况下, content type 是通过在 <dfn>{{HTMLElement("form")}} 元素中设置正确的 {{htmlattrxref("enctype", "form")}} 属性, 或是在 {{HTMLElement("input") }} 和 {{HTMLElement("button")}} 元素中设置 {{htmlattrxref("formenctype", "input")}} 属性来选择的</dfn>:</p>
+
+<ul>
+ <li><code>application/</code><dfn><code>x-www-form-urlencoded</code>: 数据被编码成以 <code>'&amp;'</code> 分隔的键-值对, 同时以 <code>'='</code> 分隔键和值. 非字母或数字的字符会被 </dfn>{{glossary("percent-encoding")}}<dfn>: 这也就是为什么这种类型不支持二进制数据(应使用 <code>multipart/form-data</code> 代替).</dfn></li>
+ <li><dfn><code>multipart/form-data</code></dfn></li>
+ <li><dfn><code>text/plain</code></dfn></li>
+</ul>
+
+<p>当 POST 请求是通过除 HTML 表单之外的方式发送时, 例如使用 {{domxref("XMLHttpRequest")}}, 那么请求主体可以是任何类型.按HTTP 1.1规范中描述,POST为了以统一的方法来涵盖以下功能:</p>
+
+<ul>
+ <li>注释已有的资源</li>
+ <li>在公告板,新闻组,邮件列表或类似的文章组中发布消息;</li>
+ <li>通过注册新增用户;</li>
+ <li>向数据处理程序提供一批数据,例如提交一个表单;</li>
+ <li>通过追加操作,扩展数据库数据.</li>
+</ul>
+
+<table class="properties">
+ <tbody>
+ <tr>
+ <th scope="row">请求是否有主体</th>
+ <td>是</td>
+ </tr>
+ <tr>
+ <th scope="row">成功的响应是否有主体</th>
+ <td>是</td>
+ </tr>
+ <tr>
+ <th scope="row">{{Glossary("安全")}}</th>
+ <td>否</td>
+ </tr>
+ <tr>
+ <th scope="row">{{Glossary("幂等")}}</th>
+ <td>否</td>
+ </tr>
+ <tr>
+ <th scope="row">{{Glossary("可缓存")}}</th>
+ <td>Only if freshness information is included</td>
+ </tr>
+ <tr>
+ <th scope="row">HTML 表单是否支持</th>
+ <td>是</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">POST /index.html
+</pre>
+
+<h2 id="示例">示例</h2>
+
+<p>使用默认的 <code>application/x-www-form-urlencoded</code> 做为 content type 的简单表单:</p>
+
+<pre class="line-numbers language-html">POST / HTTP/1.1
+Host: foo.com
+Content-Type: application/x-www-form-urlencoded
+Content-Length: 13
+
+say=Hi&amp;to=Mom</pre>
+
+<p>使用 <code>multipart/form-data</code> 作为 content type 的表单:</p>
+
+<pre>POST /test.html HTTP/1.1
+Host: example.org
+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</pre>
+
+<h2 id="规范">规范</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">规范</th>
+ <th scope="col">标题</th>
+ </tr>
+ <tr>
+ <td>{{RFC("7231", "POST", "4.3.3")}}</td>
+ <td>Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p class="hidden">The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out <a href="https://github.com/mdn/browser-compat-data">https://github.com/mdn/browser-compat-data</a> and send us a pull request.</p>
+
+<p>{{Compat("http.methods.POST")}}</p>
+
+<h2 id="另见">另见</h2>
+
+<ul>
+ <li>{{HTTPHeader("Content-Type")}}</li>
+ <li>{{HTTPHeader("Content-Disposition")}}</li>
+</ul>