blob: a86b50d0f1dc3feaae863adb96ad9d1cd24050c1 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
---
title: PATCH
slug: Web/HTTP/Methods/PATCH
tags:
- HTTP
- HTTP method
- HTTP方法
- 参考
- 请求方法
translation_of: Web/HTTP/Methods/PATCH
---
<div>{{HTTPSidebar}}</div>
<p>在HTTP协议中,请求方法 <strong>PATCH </strong> 用于对资源进行部分修改。</p>
<p>在HTTP协议中, {{HTTPMethod("PUT")}} 方法已经被用来表示对资源进行整体覆盖, 而 {{HTTPMethod("POST")}} 方法则没有对标准的补丁格式的提供支持。不同于 <code>PUT </code>方法,而与 <code>POST </code>方法类似,<code>PATCH</code> 方法是非幂等的,这就意味着连续多个的相同请求会产生不同的效果。</p>
<p>要判断一台服务器是否支持 <code>PATCH </code>方法,那么就看它是否将其添加到了响应首部 {{HTTPHeader("Allow")}} 或者 {{HTTPHeader("Access-Control-Allow-Methods")}} (在跨域访问的场合,CORS)的方法列表中 。</p>
<p>另外一个支持 PATCH 方法的隐含迹象是 {{HTTPHeader("Accept-Patch")}} 首部的出现,这个首部明确了服务器端可以接受的补丁文件的格式。</p>
<table class="properties">
<tbody>
<tr>
<th scope="row">Request has body</th>
<td>Yes</td>
</tr>
<tr>
<th scope="row">Successful response has body</th>
<td>No</td>
</tr>
<tr>
<th scope="row">{{Glossary("Safe")}}</th>
<td>No</td>
</tr>
<tr>
<th scope="row">{{Glossary("Idempotent")}}</th>
<td>No</td>
</tr>
<tr>
<th scope="row">{{Glossary("Cacheable")}}</th>
<td>No</td>
</tr>
<tr>
<th scope="row">Allowed in <a href="/en-US/docs/Web/Guide/HTML/Forms">HTML forms</a></th>
<td>No</td>
</tr>
</tbody>
</table>
<h2 id="语法">语法</h2>
<pre class="syntaxbox">PATCH /file.txt HTTP/1.1
</pre>
<h2 id="示例">示例</h2>
<h3 id="请求">请求</h3>
<pre class="line-numbers language-html">PATCH /file.txt HTTP/1.1
Host: www.example.com
Content-Type: application/example
If-Match: "e0023aa4e"
Content-Length: 100
[description of changes]</pre>
<h3 id="响应">响应</h3>
<p> {{HTTPStatus("204")}} 状态码表示这是一个操作成功的响应,因为响应中不带有消息主体。</p>
<pre class="newpage">HTTP/1.1 204 No Content
Content-Location: /file.txt
ETag: "e0023aa4f"</pre>
<h2 id="规范">规范</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Specification</th>
<th scope="col">Title</th>
</tr>
<tr>
<td>{{RFC("5789", "PATCH")}}</td>
<td>PATCH Method for HTTP</td>
</tr>
</tbody>
</table>
<h2 id="相关内容">相关内容</h2>
<ul>
<li>{{HTTPStatus("204")}}</li>
<li>{{HTTPHeader("Allow")}}, {{HTTPHeader("Access-Control-Allow-Methods")}}</li>
<li>{{HTTPHeader("Accept-Patch")}} – 用于明确服务器端可以接受的补丁文件的格式。</li>
</ul>
|