diff options
author | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
---|---|---|
committer | Peter Bengtsson <mail@peterbe.com> | 2020-12-08 14:40:17 -0500 |
commit | 33058f2b292b3a581333bdfb21b8f671898c5060 (patch) | |
tree | 51c3e392513ec574331b2d3f85c394445ea803c6 /files/zh-cn/glossary/preflight_request | |
parent | 8b66d724f7caf0157093fb09cfec8fbd0c6ad50a (diff) | |
download | translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.gz translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.tar.bz2 translated-content-33058f2b292b3a581333bdfb21b8f671898c5060.zip |
initial commit
Diffstat (limited to 'files/zh-cn/glossary/preflight_request')
-rw-r--r-- | files/zh-cn/glossary/preflight_request/index.html | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/files/zh-cn/glossary/preflight_request/index.html b/files/zh-cn/glossary/preflight_request/index.html new file mode 100644 index 0000000000..fcb8cd1028 --- /dev/null +++ b/files/zh-cn/glossary/preflight_request/index.html @@ -0,0 +1,36 @@ +--- +title: Preflight request +slug: Glossary/Preflight_request +translation_of: Glossary/Preflight_request +--- +<p> </p> + +<p>一个 CORS 预检请求是用于检查服务器是否支持 {{Glossary("CORS")}} 即跨域资源共享。</p> + +<p>它一般是用了以下几个 HTTP 请求首部的 {{HTTPMethod("OPTIONS")}} 请求:{{HTTPHeader("Access-Control-Request-Method")}} 和 {{HTTPHeader("Access-Control-Request-Headers")}},以及一个 {{HTTPHeader("Origin")}} 首部。</p> + +<p>当有必要的时候,浏览器会自动发出一个预检请求;所以在正常情况下,前端开发者不需要自己去发这样的请求。</p> + +<p>举个例子,一个客户端可能会在实际发送一个 <code>DELETE</code> 请求之前,先向服务器发起一个预检请求,用于询问是否可以向服务器发起一个 {{HTTPMethod("DELETE")}} 请求:</p> + +<pre>OPTIONS /resource/foo +Access-Control-Request-Method: DELETE +Access-Control-Request-Headers: origin, x-requested-with +Origin: https://foo.bar.org +</pre> + +<p>如果服务器允许,那么服务器就会响应这个预检请求。并且其响应首部 {{HTTPHeader("Access-Control-Allow-Methods")}} 会将 <code>DELETE</code> 包含在其中:</p> + +<pre>HTTP/1.1 200 OK +Content-Length: 0 +Connection: keep-alive +Access-Control-Allow-Origin: https://foo.bar.org +Access-Control-Allow-Methods: POST, GET, OPTIONS, DELETE +Access-Control-Max-Age: 86400</pre> + +<h2 id="参见">参见</h2> + +<ul> + <li><a href="/en-US/docs/Glossary/CORS">CORS</a></li> + <li>{{HTTPMethod("OPTIONS")}}</li> +</ul> |