From 33058f2b292b3a581333bdfb21b8f671898c5060 Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Tue, 8 Dec 2020 14:40:17 -0500 Subject: initial commit --- files/zh-cn/web/http/methods/put/index.html | 101 ++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 files/zh-cn/web/http/methods/put/index.html (limited to 'files/zh-cn/web/http/methods/put') diff --git a/files/zh-cn/web/http/methods/put/index.html b/files/zh-cn/web/http/methods/put/index.html new file mode 100644 index 0000000000..eeddfdd5c8 --- /dev/null +++ b/files/zh-cn/web/http/methods/put/index.html @@ -0,0 +1,101 @@ +--- +title: PUT +slug: Web/HTTP/Methods/PUT +tags: + - HTTP + - HTTP method + - Request method + - put +translation_of: Web/HTTP/Methods/PUT +--- +
{{HTTPSidebar}}
+ +

HTTP PUT 请求方法使用请求中的负载创建或者替换目标资源。

+ +

PUT 与 {{HTTPMethod("POST")}} 方法的区别在于,PUT方法是幂等的:调用一次与连续调用多次是等价的(即没有副作用),而连续调用多次POST方法可能会有副作用,比如将一个订单重复提交多次。

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Request has bodyYes
Successful response has bodyNo
{{Glossary("Safe")}}No
{{Glossary("Idempotent")}}Yes
{{Glossary("Cacheable")}}No
Allowed in HTML formsNo
+ +

语法

+ +
PUT /new.html HTTP/1.1
+
+ +

示例

+ +

请求

+ +
PUT /new.html HTTP/1.1
+Host: example.com
+Content-type: text/html
+Content-length: 16
+
+<p>New File</p>
+ +

应答

+ +

如果目标资源不存在,并且PUT方法成功创建了一份,那么源头服务器必须返回{{HTTPStatus("201")}} (Created) 来通知客户端资源已创建。

+ +
HTTP/1.1 201 Created
+Content-Location: /new.html
+ +

如果目标资源已经存在,并且依照请求中封装的表现形式成功进行了更新,那么,源头服务器必须返回{{HTTPStatus("200")}} (OK) 或者{{HTTPStatus("204")}} (No Content) 来表示请求的成功完成。

+ +
HTTP/1.1 204 No Content
+Content-Location: /existing.html
+
+ +

规范

+ + + + + + + + + + + + +
SpecificationTitle
{{RFC("7231", "PUT", "4.3.4")}}Hypertext Transfer Protocol (HTTP/1.1): Semantics and Content
+ +

浏览器兼容性

+ + + +

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

+ +

参见

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