aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/http
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-cn/web/http')
-rw-r--r--files/zh-cn/web/http/basics_of_http/data_uris/index.html (renamed from files/zh-cn/web/http/data_uris/index.html)0
-rw-r--r--files/zh-cn/web/http/caching/index.html (renamed from files/zh-cn/web/http/caching_faq/index.html)0
-rw-r--r--files/zh-cn/web/http/content_negotiation/list_of_default_accept_values/index.html (renamed from files/zh-cn/web/http/content_negotiation/accept_默认值/index.html)0
-rw-r--r--files/zh-cn/web/http/cors/errors/corsmissingallowcredentials/index.html (renamed from files/zh-cn/web/http/cors/errors/cors错误允许凭证/index.html)0
-rw-r--r--files/zh-cn/web/http/cors/index.html (renamed from files/zh-cn/web/http/access_control_cors/index.html)0
-rw-r--r--files/zh-cn/web/http/feature_policy/index.html (renamed from files/zh-cn/web/http/策略特征/index.html)0
-rw-r--r--files/zh-cn/web/http/feature_policy/using_feature_policy/index.html (renamed from files/zh-cn/web/http/策略特征/using_feature_policy/index.html)0
-rw-r--r--files/zh-cn/web/http/headers/strict-transport-security/index.html (renamed from files/zh-cn/web/http/http_strict_transport_security/index.html)0
-rw-r--r--files/zh-cn/web/http/headers/x-dns-prefetch-control/index.html97
-rw-r--r--files/zh-cn/web/http/headers/x-frame-options/index.html (renamed from files/zh-cn/web/http/x-frame-options/index.html)0
-rw-r--r--files/zh-cn/web/http/http_response_codes/index.html13
-rw-r--r--files/zh-cn/web/http/proxy_servers_and_tunneling/proxy_auto-configuration_pac_file/index.html (renamed from files/zh-cn/web/http/proxy_servers_and_tunneling/proxy_auto-configuration_(pac)_file/index.html)0
-rw-r--r--files/zh-cn/web/http/server-side_access_control/index.html249
-rw-r--r--files/zh-cn/web/http/跨域资源共享(cors)_/index.html544
14 files changed, 97 insertions, 806 deletions
diff --git a/files/zh-cn/web/http/data_uris/index.html b/files/zh-cn/web/http/basics_of_http/data_uris/index.html
index 5153482967..5153482967 100644
--- a/files/zh-cn/web/http/data_uris/index.html
+++ b/files/zh-cn/web/http/basics_of_http/data_uris/index.html
diff --git a/files/zh-cn/web/http/caching_faq/index.html b/files/zh-cn/web/http/caching/index.html
index 3bf85cb945..3bf85cb945 100644
--- a/files/zh-cn/web/http/caching_faq/index.html
+++ b/files/zh-cn/web/http/caching/index.html
diff --git a/files/zh-cn/web/http/content_negotiation/accept_默认值/index.html b/files/zh-cn/web/http/content_negotiation/list_of_default_accept_values/index.html
index 9db5868657..9db5868657 100644
--- a/files/zh-cn/web/http/content_negotiation/accept_默认值/index.html
+++ b/files/zh-cn/web/http/content_negotiation/list_of_default_accept_values/index.html
diff --git a/files/zh-cn/web/http/cors/errors/cors错误允许凭证/index.html b/files/zh-cn/web/http/cors/errors/corsmissingallowcredentials/index.html
index 8a8f8d0074..8a8f8d0074 100644
--- a/files/zh-cn/web/http/cors/errors/cors错误允许凭证/index.html
+++ b/files/zh-cn/web/http/cors/errors/corsmissingallowcredentials/index.html
diff --git a/files/zh-cn/web/http/access_control_cors/index.html b/files/zh-cn/web/http/cors/index.html
index c7acc1344d..c7acc1344d 100644
--- a/files/zh-cn/web/http/access_control_cors/index.html
+++ b/files/zh-cn/web/http/cors/index.html
diff --git a/files/zh-cn/web/http/策略特征/index.html b/files/zh-cn/web/http/feature_policy/index.html
index 90e83fb04a..90e83fb04a 100644
--- a/files/zh-cn/web/http/策略特征/index.html
+++ b/files/zh-cn/web/http/feature_policy/index.html
diff --git a/files/zh-cn/web/http/策略特征/using_feature_policy/index.html b/files/zh-cn/web/http/feature_policy/using_feature_policy/index.html
index 9a37fa46f3..9a37fa46f3 100644
--- a/files/zh-cn/web/http/策略特征/using_feature_policy/index.html
+++ b/files/zh-cn/web/http/feature_policy/using_feature_policy/index.html
diff --git a/files/zh-cn/web/http/http_strict_transport_security/index.html b/files/zh-cn/web/http/headers/strict-transport-security/index.html
index d890b429ef..d890b429ef 100644
--- a/files/zh-cn/web/http/http_strict_transport_security/index.html
+++ b/files/zh-cn/web/http/headers/strict-transport-security/index.html
diff --git a/files/zh-cn/web/http/headers/x-dns-prefetch-control/index.html b/files/zh-cn/web/http/headers/x-dns-prefetch-control/index.html
new file mode 100644
index 0000000000..313d309ccb
--- /dev/null
+++ b/files/zh-cn/web/http/headers/x-dns-prefetch-control/index.html
@@ -0,0 +1,97 @@
+---
+title: X-DNS-Prefetch-Control
+slug: Controlling_DNS_prefetching
+tags:
+ - DNS
+ - DNS prefetch
+ - HTTP
+ - 预解析
+translation_of: Web/HTTP/Headers/X-DNS-Prefetch-Control
+---
+<p>{{HTTPSidebar}}</p>
+
+<p><strong><code>X-DNS-Prefetch-Control</code></strong> 头控制着浏览器的 DNS 预读取功能。 DNS 预读取是一项使浏览器主动去执行域名解析的功能,其范围包括文档的所有链接,无论是图片的,CSS 的,还是 JavaScript 等其他用户能够点击的 URL。</p>
+
+<p>因为预读取会在后台执行,所以 {{glossary("DNS")}} 很可能在链接对应的东西出现之前就已经解析完毕。这能够减少用户点击链接时的延迟。</p>
+
+<table class="properties">
+ <tbody>
+ <tr>
+ <th scope="row">Header type</th>
+ <td>{{Glossary("Response header")}}</td>
+ </tr>
+ <tr>
+ <th scope="row">{{Glossary("Forbidden header name")}}</th>
+ <td>no</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="语法">语法</h2>
+
+<pre class="syntaxbox">X-DNS-Prefetch-Control: on
+X-DNS-Prefetch-Control: off
+</pre>
+
+<h3 id="参数">参数</h3>
+
+<dl>
+ <dt>on</dt>
+ <dd>启用 DNS 预解析。在浏览器支持 DNS 预解析的特性时即使不使用该标签浏览器依然会进行预解析。</dd>
+ <dt>off</dt>
+ <dd>关闭 DNS 预解析。这个属性在页面上的链接并不是由你控制的或是你根本不想向这些域名引导数据时是非常有用的。</dd>
+</dl>
+
+<h2 id="介绍">介绍</h2>
+
+<p>DNS 请求需要的带宽非常小,但是延迟却有点高,这一点在手机网络上特别明显。预读取 DNS 能让延迟明显减少一些,例如在用户点击链接时。在某些情况下,延迟能减少一秒钟。 </p>
+
+<p>在某些浏览器中这个预读取的行为将会与页面实际内容并行发生(而不是串行)。正因如此,某些高延迟的域名的解析过程才不会卡住资源的加载。</p>
+
+<p>这样可以极大的加速(尤其是移动网络环境下)页面的加载。在某些图片较多的页面中,在发起图片加载请求之前预先把域名解析好将会有至少 5% 的图片加载速度提升。</p>
+
+<h3 id="在浏览器中设置预读取配置">在浏览器中设置预读取配置</h3>
+
+<p>一般来说并不需要去管理预读取,但是可能会有用户希望关闭预读取功能。这时只需要将 <code>network.dns.disablePrefetch</code> 选项值设置为 <code>true</code> 就可以了。</p>
+
+<p>另外,默认情况下,通过 {{glossary("HTTPS")}} 加载的页面上内嵌链接的域名并不会执行预加载。在 Firefox 浏览器中,可以通过 about:config 设置 <code>network.dns.disablePrefetchFromHTTPS</code> 值为 <code>false</code> 来改变这一默认行为。</p>
+
+<h2 id="示例">示例</h2>
+
+<h3 id="打开和关闭_DNS_预读取">打开和关闭 DNS 预读取</h3>
+
+<p>你可以通过在服务器端发送 <code>X-DNS-Prefetch-Control</code> 报头,或是在文档中使用值为 {{ htmlattrxref("http-equiv") }} 的 {{ HTMLElement("meta") }} 标签:</p>
+
+<pre>&lt;meta http-equiv="x-dns-prefetch-control" content="off"&gt;
+</pre>
+
+<p>您可以通过将 <code>content</code> 的参数设置为“<code>on</code>”来改变设置。</p>
+
+<h3 id="强制查询特定主机名">强制查询特定主机名</h3>
+
+<p>你可以通过使用 {{ htmlattrxref("rel","link") }} 属性值为 <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Link_types">link type</a> 中的 <code>dns-prefetch</code> 的 {{ HTMLElement("link") }} 标签来对特定域名进行预读取:</p>
+
+<pre class="brush: html">&lt;link rel="dns-prefetch" href="http://www.spreadfirefox.com/"&gt;
+</pre>
+
+<p>在这个例子中,Firefox 将预解析域名"<a class="linkification-ext external" href="http://www.spreadfirefox.com" title="Linkification: http://www.spreadfirefox.com">www.spreadfirefox.com</a>"。</p>
+
+<p>而且,{{ HTMLElement("link") }} 元素也可以使用不完整的 URL 的主机名来标记预解析,但这些主机名前必需要有双斜线:</p>
+
+<pre class="brush: html">&lt;link rel="dns-prefetch" href="//www.spreadfirefox.com"&gt;
+</pre>
+
+<p>强制对域名进行预读取在一些情况下很有用, 比如, 在网站的主页上,强制在整个网站上频繁引用的域名的预解析,即使它们不在主页本身上使用。即使主页的性能可能不受影响,这将提高整体站点性能。</p>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+
+
+<p>{{Compat("http.headers.X-DNS-Prefetch-Control")}}</p>
+
+<h2 id="参考">参考</h2>
+
+<ul>
+ <li><a class="external" href="http://bitsup.blogspot.com/2008/11/dns-prefetching-for-firefox.html">DNS Prefetching for Firefox (blog post)</a></li>
+ <li><a class="external" href="http://dev.chromium.org/developers/design-documents/dns-prefetching">Google Chrome handles DNS prefetching control</a></li>
+</ul>
diff --git a/files/zh-cn/web/http/x-frame-options/index.html b/files/zh-cn/web/http/headers/x-frame-options/index.html
index 2b6cfcda76..2b6cfcda76 100644
--- a/files/zh-cn/web/http/x-frame-options/index.html
+++ b/files/zh-cn/web/http/headers/x-frame-options/index.html
diff --git a/files/zh-cn/web/http/http_response_codes/index.html b/files/zh-cn/web/http/http_response_codes/index.html
deleted file mode 100644
index 2c0fce1058..0000000000
--- a/files/zh-cn/web/http/http_response_codes/index.html
+++ /dev/null
@@ -1,13 +0,0 @@
----
-title: HTTP response codes
-slug: Web/HTTP/HTTP_response_codes
-translation_of: Web/HTTP/Status
-translation_of_original: Web/HTTP/HTTP_response_codes
----
-<p>HTTP状态码(响应码)用来表明这个<a href="/zh-cn/HTTP" title="zh-cn/HTTP">HTTP</a> 请求是否已经成功完成.HTTP响应类型一共分五大类:消息响应,成功响应,重定向,客户端错误,服务器端错误.</p>
-<p> </p>
-<p><span class="long_text short_text" id="result_box" lang="zh-CN"><span>下表列出了</span><span>所有HTTP</span></span><span class="long_text short_text" lang="zh-CN"><span>状态码</span><span>,以及他们</span><span>各自所代表的含义</span><span>:</span></span></p>
-<table class="standard-table" style="width: 100%;"> <thead> <tr> <th scope="col">状态码  </th> <th scope="col">原因短语</th> <th scope="col">代表含义</th> <th scope="col">HTTP 版本   </th> </tr> </thead> <tbody> <tr> <th colspan="4">消息响应</th> </tr> <tr> <td id="100">100         </td> <td>Continue<br> (继续)</td> <td>客户端应当继续发送请求.这个临时响应是用来通知客户端它的部分请求已经被服务器接收,且仍未被拒绝.客户端应当继续发送请求的剩余部分,或者如果请求已经完成,忽略这个响应.服务器必须在请求完成后向客户端发送一个最终响应.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="101">101</td> <td>Switching Protocol<br> (切换协议)</td> <td>服务器已经理解了客户端的请求,并将通过Upgrade消息头通知客户端采用不同的协议来完成这个请求。在发送完这个响应最后的空行后,服务器将会切换到 在Upgrade消息头中定义的那些协议。: 只有在切换新的协议更有好处的时候才应该采取类似措施。例如,切换到新的HTTP版本比旧版本更有优势,或者切换到一个实时且同步的协议以传送利用此类特 性的资源。</td> <td>HTTP/1.1 可用</td> </tr> <tr> <th colspan="4">成功响应</th> </tr> <tr> <td id="200">200</td> <td>OK<br> (成功)</td> <td>请求成功.成功的意义根据请求所使用的方法不同而不同. <ul> <li>GET: 资源已被提取,并作为响应体传回客户端.</li> <li>HEAD: <span class="long_text short_text" id="result_box" lang="zh-CN"><span>实体</span><span>头</span><span>已作为响应头传回客户端</span></span></li> <li>POST: 经过服务器处理客户端传来的数据,适合的资源作为响应体传回客户端.</li> <li>TRACE: <span class="long_text short_text" id="result_box" lang="zh-CN"><span>服务器</span><span>收到</span><span>请求消息</span></span>作为响应体传回客户端.</li> </ul> PUT, DELETE, 和 OPTIONS 方法永远不会返回 200 状态码.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="201">201</td> <td>Created<br> (已创建)</td> <td>请求成功,而且有一个新的资源已经依据请求的需要而建立,通常这是 PUT 方法得到的响应码.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="202">202</td> <td>Accepted<br> (已创建)</td> <td>服务器已接受请求,但尚未处理。正如它可能被拒绝一样,最终该请求可能会也可能不会被执行。在异步操作的场合下,没有比发送这个状态码更方便的做法了。:返回202状态码的响应的目的是允许服务器接受其他过程的请求(例如某个每天只执行一次的基于批处理的操作),而不必让客户端一直保持与服务器的连接直到批处理操作全部完成。在接受请求处理并返回202状态码的响应应当在返回的实体中包含一些指示处理当前状态的信息,以及指向处理状态监视器或状态预测的指针,以便用户能够估计操作是否已经完成。</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="203">203</td> <td>Non-Authoritative Information<br> (未授权信息)</td> <td> <p>服务器已成功处理了请求,但返回的实体头部元信息不是在原始服务器上有效的确定集合,而是来自本地或者第三方的拷贝,如果不是上述情况,使用200状态码才是最合适的.</p> </td> <td>HTTP/0.9 and 1.1</td> </tr> <tr> <td id="204">204</td> <td>No Content<br> (无内容)</td> <td>该响应没有响应内容,只有响应头,响应头也可能是有用的.用户代理可以根据新的响应头来更新对应资源的缓存信息.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="205">205</td> <td>Reset Content<br> (重置内容)</td> <td>告诉用户代理去重置发送该请求的窗口的文档视图.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="206">206</td> <td>Partial Content<br> (部分内容)</td> <td>当客户端通过使用range头字段进行文件分段下载时使用该状态码</td> <td>HTTP/1.1 可用</td> </tr> <tr> <th colspan="4">重定向</th> </tr> <tr> <td id="300">300</td> <td>Multiple Choice<br> (多种选择)</td> <td>该请求有多种可能的响应,用户代理或者用户必须选择它们其中的一个.服务器没有任何标准可以遵循去代替用户来进行选择.</td> <td>HTTP/1.0 and later</td> </tr> <tr> <td id="301">301</td> <td>Moved Permanently<br> (永久移动)</td> <td>该状态码表示所请求的URI资源路径已经改变,新的URL会在响应的<code>Location</code>:头字段里找到.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="302">302</td> <td>Found<br> (临时移动)</td> <td>该状态码表示所请求的URI资源路径临时改变,并且还可能继续改变.因此客户端在以后访问时还得继续使用该URI.新的URL会在响应的<code>Location:</code>头字段里找到.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="303">303</td> <td>See Other<br> (查看其他位置)</td> <td>服务器发送该响应用来引导客户端使用GET方法访问另外一个URI.</td> <td>HTTP/0.9 and 1.1</td> </tr> <tr> <td id="304">304</td> <td>Not Modified<br> (未修改)</td> <td>告诉客户端,所请求的内容距离上次访问并没有变化. 客户端可以直接从浏览器缓存里获取该资源.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="305">305</td> <td>Use Proxy<br> (使用代理)</td> <td>所请求的资源必须统过代理才能访问到.由于安全原因,该状态码并未受到广泛支持.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="306">306</td> <td><em>unused</em><br> (未使用)</td> <td><span class="long_text short_text" id="result_box" lang="zh-CN"><span>这个</span><span>状态码</span><span>已经不再被使用</span><span>,</span><span>当初它被用</span><span>在</span><span>HTTP 1.1规范</span><span>的</span><span>旧版本</span><span>中.</span></span></td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="307">307</td> <td>Temporary Redirect<br> (临时重定向)</td> <td> <p>服务器发送该响应用来引导客户端使用相同的方法访问另外一个URI来获取想要获取的资源.新的URL会在响应的<code>Location:</code>头字段里找到.与302状态码有相同的语义,且前后两次访问必须使用相同的方法(GET POST).</p> </td> <td>HTTP/1.1 可用</td> </tr> <tr> <td>308</td> <td>Permanent Redirect<br> (永久重定向)</td> <td> <p>所请求的资源将永久的位于另外一个URI上.新的URL会在响应的<code>Location:</code>头字段里找到.与301状态码有相同的语义,且前后两次访问必须使用相同的方法(GET POST).</p> <div class="note"><strong>注意:</strong> 这是个试验性的状态码,这里是<a class="external" href="http://greenbytes.de/tech/webdav/#draft-reschke-http-status-308" title="http://greenbytes.de/tech/webdav/#draft-reschke-http-status-308">规范草案</a>. <a href="/en/Firefox_14_for_developers" title="en/Firefox_14_for_developers">Firefox14</a>已经实现对该状态码的支持.</div> </td> <td> <p>HTTPbis <a class="external" href="http://greenbytes.de/tech/webdav/draft-reschke-http-status-308-05.html" title="http://greenbytes.de/tech/webdav/draft-reschke-http-status-308-05.html"></a><br> (试验草案)</p> </td> </tr> <tr> <th colspan="4">客户端错误</th> </tr> <tr> <td id="400">400</td> <td>Bad Request<br> (错误请求)</td> <td>因发送的请求语法错误,服务器无法正常读取.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="401">401</td> <td>Unauthorized<br> (未授权)</td> <td>需要身份验证后才能获取所请求的内容,类似于403错误.不同点是.401错误后,只要正确输入帐号密码,验证即可通过.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="402">402</td> <td>Payment Required<br> (需要付款)</td> <td><span class="long_text" id="result_box" lang="zh-CN"><span>该状态</span><span>码</span><span>被保留以</span><span>供将来使用.</span><span>创建此代码</span><span>最初的目的是</span><span>为</span><span>数字</span><span>支付系统而用</span><span>,</span><span>然而,到现在也没投入使用</span><span>.</span></span></td> <td>HTTP/0.9 and 1.1</td> </tr> <tr> <td id="403">403</td> <td>Forbidden<br> (禁止访问)</td> <td>客户端没有权利访问所请求内容,服务器拒绝本次请求.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="404">404</td> <td>Not Found<br> (未找到)</td> <td>服务器找不到所请求的资源.由于经常发生此种情况,所以该状态码在上网时是非常常见的.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="405">405</td> <td>Method Not Allowed<br> (不允许使用该方法)</td> <td>该请求使用的方法被服务器端禁止使用,RFC2616中规定, <code>GET</code> 和 <code>HEAD</code> 方法不能被禁止.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="406">406</td> <td>Not Acceptable<br> (无法接受)</td> <td>在进行<a href="/zh-cn/HTTP/Content_negotiation#Server-driven_negotiation" title="https://developer.mozilla.org/zh-cn/HTTP/Content_negotiation#Server-driven_negotiation"><span class="st">服务器驱动内容协商</span></a>后,没有发现合适的内容传回给客户端.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="407">407</td> <td>Proxy Authentication Required<br> (要求代理身份验证)</td> <td> <p>类似于状态码 401,不过需要通过代理才能进行验证.</p> </td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="408">408</td> <td>Request Timeout<br> (请求超时)</td> <td>客户端没有在服务器预备等待的时间内完成一个请求的发送.这意味着服务器将会切断和客户端的连接. 在其他浏览器中,这种响应更常见一些, 例如Chrome 和 IE9, 目的是为了使用 <a class="external" href="http://www.belshe.com/2011/02/10/the-era-of-browser-preconnect/" title="http://www.belshe.com/2011/02/10/the-era-of-browser-preconnect/">HTTP 预连机制</a> <span class="long_text short_text" id="result_box" lang="zh-CN"><span>加快浏览速度</span></span> (查看{{ bug("634278") }}, Firefox在未来版本中会实现这种机制). 同时注意,一些服务器不发送此种响应就直接切断连接.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="409">409</td> <td>Conflict<br> (冲突)</td> <td>该请求与服务器的当前状态所冲突.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="410">410</td> <td>Gone<br> (已失效)</td> <td>所请求的资源已经被删除.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="411">411</td> <td>Length Required<br> (需要内容长度头)</td> <td>因服务器在本次请求中需要 <code>Content-Length</code> 头字段,而客户端没有发送.所以,服务器拒绝了该请求.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="412">412</td> <td>Precondition Failed<br> (预处理失败)</td> <td>服务器没能满足客户端在获取资源时在请求头字段中设置的先决条件.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="413">413</td> <td>Request Entity Too Large<br> (请求实体过长)</td> <td>请求实体大小超过服务器的设置的最大限制,服务器可能会关闭HTTP链接并返回<code>Retry-After</code> 头字段.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="414">414</td> <td>Request-URI Too Long<br> (请求网址过长)</td> <td>客户端请求所包含的URI地址太长,以至于服务器无法处理.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="415">415</td> <td>Unsupported Media Type<br> (媒体类型不支持)</td> <td>服务器不支持客户端所请求的媒体类型,因此拒绝该请求.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="416">416</td> <td>Requested Range Not Satisfiable<br> (请求范围不合要求)</td> <td>请求中包含的<code>Range</code>头字段无法被满足,通常是因为<code>Range</code>中的数字范围超出所请求资源的大小.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="417">417</td> <td>Expectation Failed<br> (预期结果失败)</td> <td>在请求头<code> Expect</code> 中指定的预期内容无法被服务器满足.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <th colspan="4">服务器端错误</th> </tr> <tr> <td id="500">500</td> <td>Internal Server Error<br> (内部服务器错误)</td> <td>服务器遇到未知的无法解决的问题.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="501">501</td> <td>Implemented<br> (未实现)</td> <td>服务器不支持该请求中使用的方法,比如<code>POST</code> 和 <code>PUT.只有</code><code>GET</code> 和 <code>HEAD</code> 是RFC2616规范中规定服务器必须实现的方法.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="502">502</td> <td>Bad Gateway<br> (网关错误)</td> <td>服务器作为网关且从上游<span class="st">服务器获取到了一个无效的HTTP响应</span>.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="503">503</td> <td>Service Unavailable<br> (服务不可用)</td> <td>由于临时的服务器维护或者过载,服务器当前无法处理请求.这个状况是临时的,并且将在一段时间以后恢复.如果能够预计延迟时间,那么响应中可以包含一个<code>Retry-After:</code>头用以标明这个延迟时间.如果没有给出这个<code>Retry-After:</code>信息,那么客户端应当以处理500响应的方式处理它.同时,这种情况下,一个友好的用于解释服务器出现问题的页面应当被返回,并且,缓存相关的HTTP头信息也应该包含,因为通常这种错误提示网页不应当被客户端缓存.</td> <td>HTTP/0.9 可用</td> </tr> <tr> <td id="504">504</td> <td>Gateway Timeout <br> (网关超时)</td> <td>服务器作为网关且不能从上游<span class="st">服务器</span>及时的得到响应返回给客户端.</td> <td>HTTP/1.1 可用</td> </tr> <tr> <td id="505">505</td> <td>HTTP Version Not Supported<br> (HTTP版本不受支持)</td> <td>服务器不支持客户端发送的HTTP请求中所使用的HTTP协议版本.</td> <td>HTTP/1.1 可用 </td> </tr> </tbody>
-</table>
-<p> </p>
-<p>{{ languages( { "en": "en/HTTP/HTTP_response_codes"} ) }}</p>
diff --git a/files/zh-cn/web/http/proxy_servers_and_tunneling/proxy_auto-configuration_(pac)_file/index.html b/files/zh-cn/web/http/proxy_servers_and_tunneling/proxy_auto-configuration_pac_file/index.html
index e64b1758ff..e64b1758ff 100644
--- a/files/zh-cn/web/http/proxy_servers_and_tunneling/proxy_auto-configuration_(pac)_file/index.html
+++ b/files/zh-cn/web/http/proxy_servers_and_tunneling/proxy_auto-configuration_pac_file/index.html
diff --git a/files/zh-cn/web/http/server-side_access_control/index.html b/files/zh-cn/web/http/server-side_access_control/index.html
deleted file mode 100644
index 50a52b3405..0000000000
--- a/files/zh-cn/web/http/server-side_access_control/index.html
+++ /dev/null
@@ -1,249 +0,0 @@
----
-title: Server-Side Access Control
-slug: Web/HTTP/Server-Side_Access_Control
-tags:
- - AJAX
- - CORS
- - HTTP
- - PHP
-translation_of: Web/HTTP/CORS
-translation_of_original: Web/HTTP/Server-Side_Access_Control
----
-<p>{{HTTPSidebar}}</p>
-
-<p>浏览器会针对从 {{domxref("XMLHttpRequest")}} 或<a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch API</a>中发起的跨网站请求发送特定的<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers">HTTP标头</a>。它还希望看到使用跨站点响应发送回的特定HTTP标头。这些标头的概述,包括启动请求和处理来自服务器的响应的示例JavaScript代码, 以及每个头的讨论,可以在HTTP访问控制(<a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS">CORS</a>)文章中找到,应该作为本文的配套文章阅读。</p>
-
-<p>HTTP访问控制文章是很好的使用指南。本文介绍利用PHP处理访问控制请求和制定访问控制响应。本文的目标读者是服务器程序员或管理员。虽然在PHP代码示例所示,类似的概念适用于ASP.net,Perl、Python、Java等;一般来说,这些概念可以应用于任何服务器端编程环境处理HTTP请求和动态制定的HTTP响应。</p>
-
-<h3 id="讨论HTTP标头"><strong>讨论HTTP标头</strong></h3>
-
-<p>了解HTTP 头部信息, 建议先阅读这篇文章 <a href="https://developer.mozilla.org/En/HTTP_access_control">covering the HTTP headers used by both clients (such as Firefox 3.5 and beyond) and servers</a></p>
-
-<div> </div>
-
-<h3 id="工作代码示例"><strong>工作代码示例</strong></h3>
-
-<p>随后的章节中PHP代码(和JavaScript调用服务器)可查看<a href="http://arunranga.com/examples/access-control/">相关代码</a>,这些代码在实现了XMLHttpRequest的浏览器上都可运行,像Firefox 3.5及以上。</p>
-
-<div> </div>
-
-<h3 id="简单的跨站请求"><strong>简单的跨站请求</strong></h3>
-
-<p><a class="internal" href="/En/HTTP_access_control#Simple_requests" title="En/HTTP access control#Simple requests">简单的访问控制请求</a> 在下列情况下会被发起:</p>
-
-<ul>
- <li>请求方式为 HTTP/1.1 <code style="font-style: normal;">GET </code>或者<code style="font-style: normal;"> POST</code>,如果是<code style="font-style: normal;">POST</code>,则请求的Content-Type为以下之一: <code style="font-style: normal;">application/x-www-form-urlencoded</code>, <code style="font-style: normal;">multipart/form-data</code>, 或<code style="font-style: normal;">text/plain</code></li>
- <li>在请求中,不会发送自定义的头部(如X-Modified)</li>
-</ul>
-
-<p>以下情况,请求会返回相关响应信息</p>
-
-<ul>
- <li>如果资源是允许公开访问的(就像任何允许GET访问的 HTTP资源),返回Access-Control-Allow-Origin:*头信息就足够了,除非是一些需要Cookies和HTTP身份验证信息的请求。</li>
- <li>
- <div class="tran-result">如果资源访问被限制基于相同的域名,或者如果要访问的资源需要凭证(或设置凭证),那么就有必要对请求头信息中的ORIGIN进行过滤,或者至少响应请求的来源(例如Access-Control-Allow-Origin:http://arunranga.com)。另外,将发送Access-Control-Allow-Credentials:TRUE头信息,这在后续部分将进行讨论。</div>
- </li>
-</ul>
-
-<p> <a class="internal" href="/En/HTTP_access_control#Simple_requests" title="En/HTTP access control#Simple requests">简单的访问控制请求</a> 介绍了在客户端和服务端进行信息交换的HEADER.  下面是一段用来处理简单请求的PHP代码。</p>
-
-<pre class="brush: php">&lt;?php
-
-// 我们将只授予 arunranga.com 域的访问权限,因为我们认为它通过 application/xml 方式来访问这些资源是安全的。
-
-if($_SERVER['HTTP_ORIGIN'] == "http://arunranga.com")
-{
-
- header('Access-Control-Allow-Origin: http://arunranga.com');
- header('Content-type: application/xml');
- readfile('arunerDotNetResource.xml');
-}
-else
-{
-header('Content-Type: text/html');
-echo "&lt;html&gt;";
-echo "&lt;head&gt;";
-echo " &lt;title&gt;Another Resource&lt;/title&gt;";
-echo "&lt;/head&gt;";
-echo "&lt;body&gt;",
- "&lt;p&gt;This resource behaves two-fold:";
-echo "&lt;ul&gt;",
- "&lt;li&gt;If accessed from &lt;code&gt;http://arunranga.com&lt;/code&gt; it returns an XML document&lt;/li&gt;";
-echo " &lt;li&gt;If accessed from any other origin including from simply typing in the URL into the browser's address bar,";
-echo "you get this HTML document&lt;/li&gt;",
- "&lt;/ul&gt;",
-"&lt;/body&gt;",
-"&lt;/html&gt;";
-}
-?&gt;
-</pre>
-
-<p>上面的代码通过检查浏览器发送的 <code>ORIGIN</code> 头部信息(通过<code> $_SERVER['HTTP_ORIGIN']</code> ) 是否匹配 '<a class="external" href="http://arunranga.com" rel="freelink" style="font-size: 14px; line-height: 1.5;">http://arunranga.com</a>' 得知,如果是,返回 Access-Control-Allow-Origin: <a class="external" href="http://arunranga.com" rel="freelink" style='font-size: 14px; line-height: 1.5; font-family: "Courier New","Andale Mono",monospace;'>http://arunranga.com</a> 。如果你的浏览器支持访问控制<span style="font-size: 14px; line-height: 1.5;">,你可以访问 <a class="external" href="http://arunranga.com/examples/access-control/" style="font-size: 14px; line-height: 1.5;" title="http://arunranga.com/examples/access-control/">这里 .</a></span></p>
-
-<h3 id="预请求"><strong>预请求</strong></h3>
-
-<p><a class="internal" href="/En/HTTP_access_control#Preflighted_requests" title="En/HTTP access control#Preflighted requests">预请求</a> 发生在下列情况中:</p>
-
-<ul>
- <li>使用GET或POST以外的方法;利用POST发送<code style="font-style: normal;">application/x-www-form-urlencoded</code>, <code style="font-style: normal;">multipart/form-data</code>, or <code style="font-style: normal;">text/plain</code>之外的Content-Type;例如,post body的Content-type为<code style="font-style: normal;">application/xml</code></li>
- <li>发送自定义的头信息,如x-pingaruner</li>
-</ul>
-
-<p><a class="internal" href="/En/HTTP_access_control#Preflighted_requests" title="En/HTTP access control#Preflighted requests">预请求访问控制</a> 这篇文章介绍了在客户端和服务器间进行交换的<span style="font-size: 14px; line-height: 1.5;">头信息,响应preflight requests请求的服务器资源会有这些动作:</span></p>
-
-<ul>
- <li> 基于 <code>ORIGIN </code>进行过滤</li>
- <li> preflight请求的响应内容,包括必要的 <code>Access-Control-Allow-Methods</code>, <code>Access-Control-Allow-Headers</code> (保证系统正常运行),如果需要凭据的话,也会包括 <code>Access-Control-Allow-Credentials </code>头信息</li>
- <li>响应实际请求,包括处理 POST数据等。</li>
-</ul>
-
-<p>下面是相关的PHP内容, <a class="internal" href="/En/HTTP_access_control#Preflighted_requests" title="En/HTTP access control#Preflighted requests">preflighted request</a>:</p>
-
-<pre class="brush: php">&lt;?php
-if($_SERVER['REQUEST_METHOD'] == "GET")
-{
-    header('Content-Type: text/plain');
-    echo "This HTTP resource is designed to handle POSTed XML input from arunranga.com and not be retrieved with GET";
-
-}
-elseif($_SERVER['REQUEST_METHOD'] == "OPTIONS")
-{
-    // 告诉客户端我们支持来自 arunranga.com 的请求并且预请求有效期将仅有20天
-    if($_SERVER['HTTP_ORIGIN'] == "http://arunranga.com")
-    {
-    header('Access-Control-Allow-Origin: http://arunranga.com');
-    header('Access-Control-Allow-Methods: POST, GET, OPTIONS');
-    header('Access-Control-Allow-Headers: X-PINGARUNER');
-    header('Access-Control-Max-Age: 1728000');
-    header("Content-Length: 0");
-    header("Content-Type: text/plain");
-    //exit(0);
-    }
-    else
-    {
-    header("HTTP/1.1 403 Access Forbidden");
-    header("Content-Type: text/plain");
-    echo "You cannot repeat this request";
-
-    }
-}
-elseif($_SERVER['REQUEST_METHOD'] == "POST")
-{
-    /* 通过首先获得XML传送过来的blob来处理POST请求,然后做一些处理, 最后将结果返回客户端
-    */
-    if($_SERVER['HTTP_ORIGIN'] == "http://arunranga.com")
-    {
-            $postData = file_get_contents('php://input');
-            $document = simplexml_load_string($postData);
-
- // 对POST过来的数据进行一些处理
-
-            $ping = $_SERVER['HTTP_X_PINGARUNER'];
-
-
-            header('Access-Control-Allow-Origin: http://arunranga.com');
-            header('Content-Type: text/plain');
-            echo // 处理之后的一些响应
-    }
-    else
-        die("POSTing Only Allowed from arunranga.com");
-}
-else
-    die("No Other Methods Allowed");
-
-?&gt;
-</pre>
-
-<p>可以看到,就像POST一样,针对OPTIONS preflight请求,同样返回对应的头信息。这样 以来,处理preflight就像处理普通的request请求一样,在针对OPTIONS请求的响应信息中,服务器通过客户端,实际的请求可以用POST的形式发送,同时可附加X-PINGARUNERP这样的头信息。如果浏览器支持的话,可访问<a class="external" href="http://arunranga.com/examples/access-control/" style="line-height: 1.5;" title="http://arunranga.com/examples/access-control/"> 这里</a></p>
-
-<h3 id="凭证请求"><strong>凭证请求</strong></h3>
-
-<p>带凭据的请求,将Cookies和HTTP认证信息一起发送出去的跨域请求,根据请求方式,可以是<span style="line-height: 1.5;"> </span><a class="internal" href="/En/HTTP_access_control#Simple_requests" style="line-height: 1.5;" title="En/HTTP access control#Simple requests">Simple</a><span style="line-height: 1.5;"> 或 </span><a class="internal" href="/En/HTTP_access_control#Preflighted_requests" style="line-height: 1.5;" title="En/HTTP access control#Preflighted requests">Preflighted</a><span style="line-height: 1.5;">,</span></p>
-
-<p>发送 <a class="internal" href="/En/HTTP_access_control#Simple%20requests" title="En/HTTP access control#Simple requests">简单请求</a> 时, Firefox 3.5 (或以上)会发送带Cookies信息的请求,  (如果<code>withCredentials</code> 设以true). 如果服务器响应真的是可信任的, 客户端接受并进行输出。 在 <a class="internal" href="/En/HTTP_access_control#Preflighted%20requests" title="En/HTTP access control#Preflighted requests">预请求</a> 中,服务器可以<span style="line-height: 1.5;">针对</span><span style="line-height: 1.5;"> </span><code style="font-style: normal; line-height: 1.5;">OPTIONS</code><span style="line-height: 1.5;"> 请求,返回</span><span style="line-height: 1.5;"> </span><code style="font-style: normal; line-height: 1.5;">Access-Control-Allow-Credentials: true</code><span style="line-height: 1.5;"> 信息</span></p>
-
-<p>下面是处理请求的PHP内容:</p>
-
-<pre class="brush: php">&lt;?php
-
-if($_SERVER['REQUEST_METHOD'] == "GET")
-{
-
- // First See if There Is a Cookie
- //$pageAccess = $_COOKIE['pageAccess'];
- if (!isset($_COOKIE["pageAccess"])) {
-
- setcookie("pageAccess", 1, time()+2592000);
- header('Access-Control-Allow-Origin: http://arunranga.com');
- header('Cache-Control: no-cache');
- header('Pragma: no-cache');
- header('Access-Control-Allow-Credentials: true');
- header('Content-Type: text/plain');
- echo 'I do not know you or anyone like you so I am going to mark you with a Cookie :-)';
-
- }
- else
- {
-
- $accesses = $_COOKIE['pageAccess'];
- setcookie('pageAccess', ++$accesses, time()+2592000);
- header('Access-Control-Allow-Origin: http://arunranga.com');
- header('Access-Control-Allow-Credentials: true');
- header('Cache-Control: no-cache');
- header('Pragma: no-cache');
- header('Content-Type: text/plain');
- echo 'Hello -- I know you or something a lot like you! You have been to ', $_SERVER['SERVER_NAME'], ' at least ', $accesses-1, ' time(s) before!';
- }
-
-}
-elseif($_SERVER['REQUEST_METHOD'] == "OPTIONS")
-{
- // Tell the Client this preflight holds good for only 20 days
- if($_SERVER['HTTP_ORIGIN'] == "http://arunranga.com")
- {
- header('Access-Control-Allow-Origin: http://arunranga.com');
- header('Access-Control-Allow-Methods: GET, OPTIONS');
- header('Access-Control-Allow-Credentials: true');
- header('Access-Control-Max-Age: 1728000');
- header("Content-Length: 0");
- header("Content-Type: text/plain");
- //exit(0);
- }
- else
- {
- header("HTTP/1.1 403 Access Forbidden");
- header("Content-Type: text/plain");
- echo "You cannot repeat this request";
-
- }
-}
-else
- die("This HTTP Resource can ONLY be accessed with GET or OPTIONS");
-
-
-
-?&gt;
-</pre>
-
-<p>需要注意的是,在带凭据请求中, <code>Access-Control-Allow-Origin:</code> 头不能是通配符 "*",必须是一个有效的域名。  可参考这里 <a class="external" href="http://arunranga.com/examples/access-control/" title="http://arunranga.com/examples/access-control/">running here</a></p>
-
-<h3 id="Apache示例"><strong>Apache示例</strong></h3>
-
-<h4 id="限制对某些URI的访问"><strong>限制对某些URI的访问</strong></h4>
-
-<p>最有效的方法之一,利用Apache rewrite, 环境变量,还有headers使<code style="font-style: normal; line-height: 1.5;">Access-Control-Allow-*</code><span style="line-height: 1.5;"> 对某些特定的URI生效,比如,以无认证信息形式利用GET跨域请求api(.*).json。</span></p>
-
-<pre>RewriteRule ^/api(.*)\.json$ /api$1.json [CORS=True]
-Header set Access-Control-Allow-Origin "*" env=CORS
-Header set Access-Control-Allow-Methods "GET" env=CORS
-Header set Access-Control-Allow-Credentials "false" env=CORS
-</pre>
-
-<h3 id="参见"><strong>参见</strong></h3>
-
-<ul>
- <li><a class="external" href="http://arunranga.com/examples/access-control/" title="http://arunranga.com/examples/access-control/">Examples of Access Control in Action</a></li>
- <li><a class="internal" href="/En/HTTP_access_control" title="En/HTTP Access Control">HTTP Access Control covering the HTTP Headers</a></li>
- <li><a class="internal" href="/en/DOM/XMLHttpRequest" title="En/XMLHttpRequest">XMLHttpRequest</a></li>
- <li><a class="external" href="http://www.webfonts.info/wiki/index.php?title=%40font-face_support_in_Firefox" title="http://www.webfonts.info/wiki/index.php?title=@font-face_support_in_Firefox">Web Fonts</a></li>
-</ul>
diff --git a/files/zh-cn/web/http/跨域资源共享(cors)_/index.html b/files/zh-cn/web/http/跨域资源共享(cors)_/index.html
deleted file mode 100644
index 5d4f591eb7..0000000000
--- a/files/zh-cn/web/http/跨域资源共享(cors)_/index.html
+++ /dev/null
@@ -1,544 +0,0 @@
----
-title: 跨域资源共享(CORS)
-slug: Web/HTTP/跨域资源共享(CORS)_
----
-<div>{{ HTTPSidebar }}</div>
-
-<div></div>
-
-<div><span class="seoSummary">跨域资源共享({{Glossary("CORS")}}) 是一种机制,它使用额外的 {{Glossary("HTTP")}} 头来告诉浏览器  让运行在一个 origin (domain) 上的Web应用被准许访问来自不同源服务器上的指定的资源。</span>当一个资源从与该资源本身所在的服务器<strong>不同的域、协议或端口</strong>请求一个资源时,资源会发起一个<strong>跨域 HTTP 请求</strong>。</div>
-
-<div></div>
-
-<div>比<font>如,站点 http://domain-a.com 的某 HTML 页面通过 <a href="/zh-CN/docs/Web/HTML/Element/Img#Attributes">&lt;img&gt; 的 src </a>请求 http://domain-b.com/image.jpg。网络</font>上的许多页面都会加载来自不同域的CSS样式表,图像和脚本等资源。</div>
-
-<div></div>
-
-<p>出于安全原因,浏览器限制从脚本内发起的跨源HTTP请求。 例如,XMLHttpRequest和Fetch API遵循同源策略。 这意味着使用这些API的Web应用程序只能从加载应用程序的同一个域请求HTTP资源,除非响应报文包含了正确CORS响应头。</p>
-
-<p>  (译者注:这段描述不准确,并不一定是浏览器限制了发起跨站请求,也可能是跨站请求可以正常发起,但是返回结果被浏览器拦截了。)</p>
-
-<p><img alt="" src="https://mdn.mozillademos.org/files/14295/CORS_principle.png" style="height: 305px; width: 440px;"></p>
-
-<p>跨域资源共享( {{Glossary("CORS")}} )机制允许 Web 应用服务器进行跨域访问控制,从而使跨域数据传输得以安全进行。现代浏览器支持在 API 容器中(例如 {{domxref("XMLHttpRequest")}} 或 <a href="/en-US/docs/Web/API/Fetch_API">Fetch</a> )使用 CORS,以降低跨域 HTTP 请求所带来的风险。</p>
-
-<h2 id="谁应该读这篇文章?">谁应该读这篇文章?</h2>
-
-<p>说实话,每个人。</p>
-
-<p>更具体地来讲,这篇文章适用于网站管理员、后端和前端开发者。现代浏览器处理跨域资源共享的客户端部分,包括HTTP头和相关策略的执行。但是这一新标准意味着服务器需要处理新的请求头和响应头。对于服务端的支持,开发者可以阅读补充材料 <a class="internal" href="https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Server-Side_Access_Control" title="En/Server-Side Access Control">cross-origin sharing from a server perspective (with PHP code snippets)</a> 。</p>
-
-<h2 id="什么情况下需要_CORS_?">什么情况下需要 CORS ?</h2>
-
-<p>跨域资源共享标准( <a class="external external-icon" href="http://www.w3.org/TR/cors/" title="http://www.w3.org/TR/cors/">cross-origin sharing standard</a> )允许在下列场景中使用跨域 HTTP 请求:</p>
-
-<ul>
- <li>前文提到的由 {{domxref("XMLHttpRequest")}} 或 <a href="https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API">Fetch</a> 发起的跨域 HTTP 请求。</li>
- <li>Web 字体 (CSS 中通过<code> @font-face </code>使用跨域字体资源), <a class="external external-icon" href="http://www.webfonts.info/wiki/index.php?title=%40font-face_support_in_Firefox" title="http://www.webfonts.info/wiki/index.php?title=@font-face_support_in_Firefox">因此,网站就可以发布 TrueType 字体资源,并只允许已授权网站进行跨站调用</a>。</li>
- <li><a href="https://developer.mozilla.org/zh-CN/docs/Web/API/WebGL_API/Tutorial/Using_textures_in_WebGL">WebGL 贴图</a></li>
- <li>使用 <code><a href="https://developer.mozilla.org/en-US/docs/Web/API/CanvasRenderingContext2D/drawImage">drawImage</a></code> 将 Images/video 画面绘制到 canvas</li>
-</ul>
-
-<p>本文概述了跨域资源共享机制及其所涉及的 HTTP 头。</p>
-
-<h2 id="功能概述">功能概述</h2>
-
-<p>跨域资源共享标准新增了一组 HTTP 首部字段,允许服务器声明哪些源站通过浏览器有权限访问哪些资源。另外,规范要求,对那些可能对服务器数据产生副作用的 HTTP 请求方法(特别是 {{HTTPMethod("GET")}} 以外的 HTTP 请求,或者搭配某些 MIME 类型的 {{HTTPMethod("POST")}} 请求),浏览器必须首先使用 {{HTTPMethod("OPTIONS")}} 方法发起一个预检请求(preflight request),从而获知服务端是否允许该跨域请求。服务器确认允许之后,才发起实际的 HTTP 请求。在预检请求的返回中,服务器端也可以通知客户端,是否需要携带身份凭证(包括 <a href="/zh-CN/docs/Web/HTTP/Cookies">Cookies </a>和 HTTP 认证相关数据)。</p>
-
-<p>CORS请求失败会产生错误,但是为了安全,在JavaScript代码层面是无法获知到底具体是哪里出了问题。你只能查看浏览器的控制台以得知具体是哪里出现了错误。</p>
-
-<p>接下来的内容将讨论相关场景,并剖析该机制所涉及的 HTTP 首部字段。</p>
-
-<h2 id="若干访问控制场景">若干访问控制场景</h2>
-
-<p>这里,我们使用三个场景来解释跨域资源共享机制的工作原理。这些例子都使用 {{domxref("XMLHttpRequest")}} 对象。</p>
-
-<p>本文中的 JavaScript 代码片段都可以从 <a href="http://arunranga.com/examples/access-control/">http://arunranga.com/examples/access-control/</a> 获得。另外,使用支持跨域  {{domxref("XMLHttpRequest")}} 的浏览器访问该地址,可以看到代码的实际运行结果。</p>
-
-<p>关于服务端对跨域资源共享的支持的讨论,请参见这篇文章: <a href="/zh-CN/docs/Web/HTTP/Server-Side_Access_Control">Server-Side_Access_Control (CORS)</a>。</p>
-
-<h3 id="简单请求">简单请求</h3>
-
-<p>某些请求不会触发 <a href="/zh-CN/docs/Web/HTTP/Access_control_CORS#Preflighted_requests">CORS 预检请求</a>。本文称这样的请求为“简单请求”,请注意,该术语并不属于 {{SpecName('Fetch')}} (其中定义了 CORS)规范。若请求满足所有下述条件,则该请求可视为“简单请求”:</p>
-
-<ul>
- <li>使用下列方法之一:
- <ul>
- <li>{{HTTPMethod("GET")}}</li>
- <li>{{HTTPMethod("HEAD")}}</li>
- <li>{{HTTPMethod("POST")}}</li>
- </ul>
- </li>
- <li><span class="short_text" id="result_box" lang="zh-CN"><span>Fetch 规范定义了</span></span><a href="https://fetch.spec.whatwg.org/#cors-safelisted-request-header">对 CORS 安全的首部字段集合</a>,不得人为设置该集合之外的其他首部字段。该集合为:
- <ul>
- <li>{{HTTPHeader("Accept")}}</li>
- <li>{{HTTPHeader("Accept-Language")}}</li>
- <li>{{HTTPHeader("Content-Language")}}</li>
- <li>{{HTTPHeader("Content-Type")}} (需要注意额外的限制)</li>
- <li><code><a href="http://httpwg.org/http-extensions/client-hints.html#dpr">DPR</a></code></li>
- <li><code><a href="http://httpwg.org/http-extensions/client-hints.html#downlink">Downlink</a></code></li>
- <li><code><a href="http://httpwg.org/http-extensions/client-hints.html#save-data">Save-Data</a></code></li>
- <li><code><a href="http://httpwg.org/http-extensions/client-hints.html#viewport-width">Viewport-Width</a></code></li>
- <li><code><a href="http://httpwg.org/http-extensions/client-hints.html#width">Width</a></code></li>
- </ul>
- </li>
- <li>{{HTTPHeader("Content-Type")}} 的值仅限于下列三者之一:
- <ul>
- <li><code>text/plain</code></li>
- <li><code>multipart/form-data</code></li>
- <li><code>application/x-www-form-urlencoded</code></li>
- </ul>
- </li>
- <li>请求中的任意{{domxref("XMLHttpRequestUpload")}} 对象均没有注册任何事件监听器;{{domxref("XMLHttpRequestUpload")}} 对象可以使用 {{domxref("XMLHttpRequest.upload")}} 属性访问。</li>
- <li>请求中没有使用 {{domxref("ReadableStream")}} 对象。</li>
-</ul>
-
-<div class="note"><strong>注意:</strong> 这些跨域请求与浏览器发出的其他跨域请求并无二致。如果服务器未返回正确的响应首部,则请求方不会收到任何数据。因此,那些不允许跨域请求的网站无需为这一新的 HTTP 访问控制特性担心。</div>
-
-<div class="note"><strong>注意:</strong> WebKit Nightly 和 Safari Technology Preview 为{{HTTPHeader("Accept")}}, {{HTTPHeader("Accept-Language")}}, 和 {{HTTPHeader("Content-Language")}} 首部字段的值添加了额外的限制。如果这些首部字段的值是“非标准”的,WebKit/Safari 就不会将这些请求视为“简单请求”。WebKit/Safari 并没有在文档中列出哪些值是“非标准”的,不过我们可以在这里找到相关讨论:<a href="https://bugs.webkit.org/show_bug.cgi?id=165178" rel="nofollow noreferrer">Require preflight for non-standard CORS-safelisted request headers Accept, Accept-Language, and Content-Language</a>, <a href="https://bugs.webkit.org/show_bug.cgi?id=165566" rel="nofollow noreferrer">Allow commas in Accept, Accept-Language, and Content-Language request headers for simple CORS</a>, and <a href="https://bugs.webkit.org/show_bug.cgi?id=166363" rel="nofollow noreferrer">Switch to a blacklist model for restricted Accept headers in simple CORS requests</a>。其它浏览器并不支持这些额外的限制,因为它们不属于规范的一部分。</div>
-
-<p>比如说,假如站点 http://foo.example 的网页应用想要访问 http://bar.other 的资源。http://foo.example 的网页中可能包含类似于下面的 JavaScript 代码:</p>
-
-<pre class="brush: js" id="line1">var invocation = new XMLHttpRequest();
-var url = 'http://bar.other/resources/public-data/';
-
-function callOtherDomain() {
- if(invocation) {
- invocation.open('GET', url, true);
- invocation.onreadystatechange = handler;
- invocation.send();
- }
-}
-</pre>
-
-<p><span class="short_text" id="result_box" lang="zh-CN"><span>客户端和服务器之间使用 CORS 首部字段来处理跨域权限:</span></span></p>
-
-<p><img alt="" src="https://mdn.mozillademos.org/files/14293/simple_req.png" style="height: 224px; width: 521px;"></p>
-
-<p>分别检视请求报文和响应报文:</p>
-
-<pre class="brush: shell">GET /resources/public-data/ HTTP/1.1
-Host: bar.other
-User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081130 Minefield/3.1b3pre
-Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
-Accept-Language: en-us,en;q=0.5
-Accept-Encoding: gzip,deflate
-Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
-Connection: keep-alive
-Referer: http://foo.example/examples/access-control/simpleXSInvocation.html
-Origin: http://foo.example
-
-
-HTTP/1.1 200 OK
-Date: Mon, 01 Dec 2008 00:23:53 GMT
-Server: Apache/2.0.61
-Access-Control-Allow-Origin: *
-Keep-Alive: timeout=2, max=100
-Connection: Keep-Alive
-Transfer-Encoding: chunked
-Content-Type: application/xml
-
-[XML Data]
-</pre>
-
-<p>第 1~10 行是请求首部。第10行 的请求首部字段 {{HTTPHeader("Origin")}} 表明该请求来源于 <code>http://foo.example</code>。</p>
-
-<p>第 13~22 行是来自于 http://bar.other 的服务端响应。响应中携带了响应首部字段 {{HTTPHeader("Access-Control-Allow-Origin")}}(第 16 行)。使用 {{HTTPHeader("Origin")}} 和 {{HTTPHeader("Access-Control-Allow-Origin")}} 就能完成最简单的访问控制。本例中,服务端返回的 <code>Access-Control-Allow-Origin: *</code> 表明,该资源可以被<strong>任意</strong>外域访问。如果服务端仅允许来自 http://foo.example 的访问,该首部字段的内容如下:</p>
-
-<p><code>Access-Control-Allow-Origin: http://foo.example</code></p>
-
-<p>现在,除了 http://foo.example,其它外域均不能访问该资源(该策略由请求首部中的 ORIGIN 字段定义,见第10行)。<code>Access-Control-Allow-Origin</code> 应当为 * 或者包含由 Origin 首部字段所指明的域名。</p>
-
-<h3 id="预检请求">预检请求</h3>
-
-<p>与前述简单请求不同,“需预检的请求”要求必须首先使用 {{HTTPMethod("OPTIONS")}}   方法发起一个预检请求到服务器,以获知服务器是否允许该实际请求。"预检请求“的使用,可以避免跨域请求对服务器的用户数据产生未预期的影响。</p>
-
-<p>当请求满足下述任一条件时,即应首先发送预检请求:</p>
-
-<ul>
- <li>使用了下面任一 HTTP 方法:
- <ul>
- <li>{{HTTPMethod("PUT")}}</li>
- <li>{{HTTPMethod("DELETE")}}</li>
- <li>{{HTTPMethod("CONNECT")}}</li>
- <li>{{HTTPMethod("OPTIONS")}}</li>
- <li>{{HTTPMethod("TRACE")}}</li>
- <li>{{HTTPMethod("PATCH")}}</li>
- </ul>
- </li>
- <li>人为设置了<a href="https://fetch.spec.whatwg.org/#cors-safelisted-request-header">对 CORS 安全的首部字段集合</a>之外的其他首部字段。该集合为:
- <ul>
- <li>{{HTTPHeader("Accept")}}</li>
- <li>{{HTTPHeader("Accept-Language")}}</li>
- <li>{{HTTPHeader("Content-Language")}}</li>
- <li>{{HTTPHeader("Content-Type")}} (需要注意额外的限制)</li>
- <li><code><a href="http://httpwg.org/http-extensions/client-hints.html#dpr">DPR</a></code></li>
- <li><code><a href="http://httpwg.org/http-extensions/client-hints.html#downlink">Downlink</a></code></li>
- <li><code><a href="http://httpwg.org/http-extensions/client-hints.html#save-data">Save-Data</a></code></li>
- <li><code><a href="http://httpwg.org/http-extensions/client-hints.html#viewport-width">Viewport-Width</a></code></li>
- <li><code><a href="http://httpwg.org/http-extensions/client-hints.html#width">Width</a></code></li>
- </ul>
- </li>
- <li> {{HTTPHeader("Content-Type")}} 的值不属于下列之一:
- <ul>
- <li><code>application/x-www-form-urlencoded</code></li>
- <li><code>multipart/form-data</code></li>
- <li><code>text/plain</code></li>
- </ul>
- </li>
- <li>请求中的{{domxref("XMLHttpRequestUpload")}} 对象注册了任意多个事件监听器。</li>
- <li>请求中使用了{{domxref("ReadableStream")}}对象。</li>
-</ul>
-
-<div class="note">
-<p><strong>注意:</strong> WebKit Nightly 和 Safari Technology Preview 为{{HTTPHeader("Accept")}}, {{HTTPHeader("Accept-Language")}}, 和 {{HTTPHeader("Content-Language")}} 首部字段的值添加了额外的限制。如果这些首部字段的值是“非标准”的,WebKit/Safari 就不会将这些请求视为“简单请求”。WebKit/Safari 并没有在文档中列出哪些值是“非标准”的,不过我们可以在这里找到相关讨论:<a href="https://bugs.webkit.org/show_bug.cgi?id=165178" rel="nofollow noreferrer">Require preflight for non-standard CORS-safelisted request headers Accept, Accept-Language, and Content-Language</a>, <a href="https://bugs.webkit.org/show_bug.cgi?id=165566" rel="nofollow noreferrer">Allow commas in Accept, Accept-Language, and Content-Language request headers for simple CORS</a>, and <a href="https://bugs.webkit.org/show_bug.cgi?id=166363" rel="nofollow noreferrer">Switch to a blacklist model for restricted Accept headers in simple CORS requests</a>。其它浏览器并不支持这些额外的限制,因为它们不属于规范的一部分。</p>
-</div>
-
-<p>如下是一个需要执行预检请求的 HTTP 请求:</p>
-
-<pre class="brush: js">var invocation = new XMLHttpRequest();
-var url = 'http://bar.other/resources/post-here/';
-var body = '&lt;?xml version="1.0"?&gt;&lt;person&gt;&lt;name&gt;Arun&lt;/name&gt;&lt;/person&gt;';
-
-function callOtherDomain(){
- if(invocation)
- {
- invocation.open('POST', url, true);
- invocation.setRequestHeader('X-PINGOTHER', 'pingpong');
- invocation.setRequestHeader('Content-Type', 'application/xml');
- invocation.onreadystatechange = handler;
- invocation.send(body);
- }
-}
-
-......
-</pre>
-
-<p>上面的代码使用 POST 请求发送一个 XML 文档,该请求包含了一个自定义的请求首部字段(X-PINGOTHER: pingpong)。另外,该请求的 Content-Type 为 application/xml。因此,该请求需要首先发起“预检请求”。</p>
-
-<p><img alt="" src="https://mdn.mozillademos.org/files/16753/preflight_correct.png" style="height: 553px; width: 521px;"></p>
-
-<pre>OPTIONS /resources/post-here/ HTTP/1.1
-Host: bar.other
-User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081130 Minefield/3.1b3pre
-Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
-Accept-Language: en-us,en;q=0.5
-Accept-Encoding: gzip,deflate
-Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
-Connection: keep-alive
-Origin: http://foo.example
-Access-Control-Request-Method: POST
-Access-Control-Request-Headers: X-PINGOTHER, Content-Type
-
-
-HTTP/1.1 200 OK
-Date: Mon, 01 Dec 2008 01:15:39 GMT
-Server: Apache/2.0.61 (Unix)
-Access-Control-Allow-Origin: http://foo.example
-Access-Control-Allow-Methods: POST, GET, OPTIONS
-Access-Control-Allow-Headers: X-PINGOTHER, Content-Type
-Access-Control-Max-Age: 86400
-Vary: Accept-Encoding, Origin
-Content-Encoding: gzip
-Content-Length: 0
-Keep-Alive: timeout=2, max=100
-Connection: Keep-Alive
-Content-Type: text/plain</pre>
-
-<p>预检请求完成之后,发送实际请求:</p>
-
-<pre><code>POST /resources/post-here/ HTTP/1.1
-Host: bar.other
-User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081130 Minefield/3.1b3pre
-Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
-Accept-Language: en-us,en;q=0.5
-Accept-Encoding: gzip,deflate
-Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
-Connection: keep-alive
-X-PINGOTHER: pingpong
-Content-Type: text/xml; charset=UTF-8
-Referer: http://foo.example/examples/preflightInvocation.html
-Content-Length: 55
-Origin: http://foo.example
-Pragma: no-cache
-Cache-Control: no-cache
-
-&lt;?xml version="1.0"?&gt;&lt;person&gt;&lt;name&gt;Arun&lt;/name&gt;&lt;/person&gt;
-
-
-HTTP/1.1 200 OK
-Date: Mon, 01 Dec 2008 01:15:40 GMT
-Server: Apache/2.0.61 (Unix)
-Access-Control-Allow-Origin: http://foo.example
-Vary: Accept-Encoding, Origin
-Content-Encoding: gzip
-Content-Length: 235
-Keep-Alive: timeout=2, max=99
-Connection: Keep-Alive
-Content-Type: text/plain
-
-[Some GZIP'd payload]</code></pre>
-
-<p>浏览器检测到,从 JavaScript 中发起的请求需要被预检。从上面的报文中,我们看到,第 1~12 行发送了一个使用 <code>OPTIONS 方法的“</code>预检请求<code>”。</code> OPTIONS 是 HTTP/1.1 协议中定义的方法,用以从服务器获取更多信息。该方法不会对服务器资源产生影响。 预检请求中同时携带了下面两个首部字段:</p>
-
-<pre><code>Access-Control-Request-Method: POST
-Access-Control-Request-Headers: X-PINGOTHER, Content-Type</code></pre>
-
-<p><code>首部字段 Access-Control-Request-Method 告知服务器,实际请求将使用 POST 方法。<font face="Open Sans, Arial, sans-serif">首部字段 </font></code><code><code>Access-Control-Request-Headers 告知服务器,实际请求将携带两个自定义请求首部字段:<code>X-PINGOTHER 与 Content-Type。服务器据此决定,该实际请求是否被允许。</code></code></code></p>
-
-<p>第14~26 行为预检请求的响应,表明服务器将接受后续的实际请求。重点看第 17~20 行:</p>
-
-<pre><code>Access-Control-Allow-Origin: http://foo.example
-Access-Control-Allow-Methods: POST, GET, OPTIONS
-Access-Control-Allow-Headers: X-PINGOTHER, Content-Type
-Access-Control-Max-Age: 86400</code></pre>
-
-<p><font face="Open Sans, Arial, sans-serif">首部字段</font><code><font face="Open Sans, Arial, sans-serif"> </font>Access-Control-Allow-Methods </code>表明服务器允许客户端使用<code> </code><code>POST,</code> <code>GET </code>和 <code>OPTIONS</code> 方法发起请求。该字段与 <a class="external" href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7" title="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.7">HTTP/1.1 Allow: response header</a> 类似,但仅限于在需要访问控制的场景中使用。</p>
-
-<p>首部字段 <code>Access-Control-Allow-Headers </code>表明服务器允许请求中携带字段 <code><code>X-PINGOTHER </code></code>与<code><code> Content-Type</code></code>。<font face="Open Sans, Arial, sans-serif">与</font><code><code><font face="Open Sans, Arial, sans-serif"> </font></code></code><code>Access-Control-Allow-Methods </code>一样,<code><code>Access-Control-Allow-Headers</code></code> 的值为逗号分割的列表。</p>
-
-<p>最后,首部字段 <code>Access-Control-Max-Age</code> 表明该响应的有效时间为 86400 秒,也就是 24 小时。在有效时间内,浏览器无须为同一请求再次发起预检请求。请注意,浏览器自身维护了一个最大有效时间,如果该首部字段的值超过了最大有效时间,将不会生效。</p>
-
-<h4 id="预检请求与重定向">预检请求与重定向</h4>
-
-<p>大多数浏览器不支持针对于预检请求的重定向。如果一个预检请求发生了重定向,浏览器将报告错误:</p>
-
-<blockquote>
-<p>The request was redirected to 'https://example.com/foo', which is disallowed for cross-origin requests that require preflight</p>
-</blockquote>
-
-<blockquote>
-<p>Request requires preflight, which is disallowed to follow cross-origin redirect</p>
-</blockquote>
-
-<p>CORS 最初要求该行为,不过<a href="https://github.com/whatwg/fetch/commit/0d9a4db8bc02251cc9e391543bb3c1322fb882f2">在后续的修订中废弃了这一要求</a>。</p>
-
-<p>在浏览器的实现跟上规范之前,有两种方式规避上述报错行为:</p>
-
-<ul>
- <li>在服务端去掉对预检请求的重定向;</li>
- <li>将实际请求变成一个简单请求。</li>
-</ul>
-
-<p>如果上面两种方式难以做到,我们仍有其他办法:</p>
-
-<ul>
- <li>发出一个简单请求(使用  <a href="/en-US/docs/Web/API/Response/url">Response.url</a> 或 <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseURL">XHR.responseURL</a>)以判断真正的预检请求会返回什么地址。</li>
- <li>发出另一个请求(真正的请求),使用在上一步通过<a href="https://developer.mozilla.org/en-US/docs/Web/API/Response/url">Response.url</a> 或 <a href="https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/responseURL">XMLHttpRequest.responseURL</a>获得的URL。</li>
-</ul>
-
-<p>不过,如果请求是由于存在 Authorization 字段而引发了预检请求,则这一方法将无法使用。这种情况只能由服务端进行更改。</p>
-
-<h3 id="附带身份凭证的请求">附带身份凭证的请求</h3>
-
-<p><a href="/en-US/docs/Web/API/Fetch_API">Fetch</a> 与 CORS 的一个有趣的特性是,可以基于  <a href="/en-US/docs/Web/HTTP/Cookies">HTTP cookies</a> 和 HTTP 认证信息发送身份凭证。一般而言,对于跨域 {{domxref("XMLHttpRequest")}} 或 <a href="/en-US/docs/Web/API/Fetch_API">Fetch</a> 请求,浏览器<strong>不会</strong>发送身份凭证信息。如果要发送凭证信息,需要设置 <code><a class="internal" href="/en/DOM/XMLHttpRequest" title="En/XMLHttpRequest">XMLHttpRequest</a> </code>的某个特殊标志位。</p>
-
-<p><code class="plain">本例中,http://foo.example 的某脚本向 <code class="plain">http://bar.other 发起一个GET 请求,并设置 Cookies:</code></code></p>
-
-<pre id="line1"><code>var invocation = new XMLHttpRequest();
-var url = 'http://bar.other/resources/credentialed-content/';
-
-function callOtherDomain(){
- if(invocation) {
- invocation.open('GET', url, true);
- invocation.withCredentials = true;
- invocation.onreadystatechange = handler;
- invocation.send();
- }
-}</code></pre>
-
-<p>第 7 行将 <code><a class="internal" href="/en/DOM/XMLHttpRequest" title="En/XMLHttpRequest">XMLHttpRequest</a> </code>的 <code>withCredentials 标志设置为 true,</code>从而向服务器发送 Cookies。因为这是一个简单 GET 请求,所以浏览器不会对其发起“预检请求”。但是,如果服务器端的响应中未携带 <code>Access-Control-Allow-Credentials: true ,浏览器将不会把响应内容返回给请求的发送者。</code></p>
-
-<p><img alt="" src="https://mdn.mozillademos.org/files/14291/cred-req.png"></p>
-
-<p>客户端与服务器端交互示例如下:</p>
-
-<pre><code>GET /resources/access-control-with-credentials/ HTTP/1.1
-Host: bar.other
-User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.1b3pre) Gecko/20081130 Minefield/3.1b3pre
-Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
-Accept-Language: en-us,en;q=0.5
-Accept-Encoding: gzip,deflate
-Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
-Connection: keep-alive
-Referer: http://foo.example/examples/credential.html
-Origin: http://foo.example
-Cookie: pageAccess=2
-
-
-HTTP/1.1 200 OK
-Date: Mon, 01 Dec 2008 01:34:52 GMT
-Server: Apache/2.0.61 (Unix) PHP/4.4.7 mod_ssl/2.0.61 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SVN/1.4.2
-X-Powered-By: PHP/5.2.6
-Access-Control-Allow-Origin: http://foo.example
-Access-Control-Allow-Credentials: true
-Cache-Control: no-cache
-Pragma: no-cache
-Set-Cookie: pageAccess=3; expires=Wed, 31-Dec-2008 01:34:53 GMT
-Vary: Accept-Encoding, Origin
-Content-Encoding: gzip
-Content-Length: 106
-Keep-Alive: timeout=2, max=100
-Connection: Keep-Alive
-Content-Type: text/plain
-
-
-[text/plain payload]</code></pre>
-
-<p>即使第 11 行指定了 Cookie 的相关信息,但是,如果 bar.other 的响应中缺失 {{HTTPHeader("Access-Control-Allow-Credentials")}}<code>: true(</code>第 19 行),则响应内容不会返回给请求的发起者。</p>
-
-<h4 id="附带身份凭证的请求与通配符">附带身份凭证的请求与通配符</h4>
-
-<p>对于附带身份凭证的请求,服务器不得设置 <code style="font-style: normal;">Access-Control-Allow-Origin 的值为“*”。</code></p>
-
-<p><code style="font-style: normal;">这是因为请求的首部中携带了 Cookie 信息,如果 Access-Control-Allow-Origin 的值为“*”,请求将会失败。而将 Access-Control-Allow-Origin 的值设置为 </code>http://foo.example,则请求将成功执行。</p>
-
-<p>另外,响应首部中也携带了 Set-Cookie 字段,尝试对 Cookie 进行修改。如果操作失败,将会抛出异常。</p>
-
-<h2 id="HTTP_响应首部字段">HTTP 响应首部字段</h2>
-
-<p>本节列出了规范所定义的响应首部字段。上一小节中,我们已经看到了这些首部字段在实际场景中是如何工作的。</p>
-
-<h3 id="Access-Control-Allow-Origin">Access-Control-Allow-Origin</h3>
-
-<p>响应首部中可以携带一个 {{HTTPHeader("Access-Control-Allow-Origin")}}<code style="font-style: normal;"> 字段,其语法如下:</code></p>
-
-<pre>Access-Control-Allow-Origin: &lt;origin&gt; | *
-</pre>
-
-<p>其中,origin 参数的值指定了允许访问该资源的外域 URI。对于不需要携带身份凭证的请求,服务器可以指定该字段的值为通配符,表示允许来自所有域的请求。</p>
-
-<p>例如,下面的字段值将允许来自 http://mozilla.com 的请求:</p>
-
-<pre>Access-Control-Allow-Origin: <span class="plain">http://mozilla.com</span></pre>
-
-<p>如果服务端指定了具体的域名而非“*”,那么响应首部中的 Vary 字段的值必须包含 Origin。这将告诉客户端:服务器对不同的源站返回不同的内容。</p>
-
-<h3 id="Access-Control-Expose-Headers">Access-Control-Expose-Headers</h3>
-
-<p>译者注:在跨域访问时,XMLHttpRequest对象的getResponseHeader()方法只能拿到一些最基本的响应头,Cache-Control、Content-Language、Content-Type、Expires、Last-Modified、Pragma,如果要访问其他头,则需要服务器设置本响应头。</p>
-
-<p>{{HTTPHeader("Access-Control-Expose-Headers")}} 头让服务器把允许浏览器访问的头放入白名单,例如:</p>
-
-<pre>Access-Control-Expose-Headers: X-My-Custom-Header, X-Another-Custom-Header
-</pre>
-
-<p>这样浏览器就能够通过getResponseHeader访问<code>X-My-Custom-Header</code>和 <code>X-Another-Custom-Header</code> 响应头了。</p>
-
-<h3 id="Access-Control-Max-Age">Access-Control-Max-Age</h3>
-
-<p>{{HTTPHeader("Access-Control-Max-Age")}} 头指定了preflight请求的结果能够被缓存多久,请参考本文在前面提到的preflight例子。</p>
-
-<pre>Access-Control-Max-Age: &lt;delta-seconds&gt;
-</pre>
-
-<p><code>delta-seconds</code> 参数表示preflight请求的结果在多少秒内有效。</p>
-
-<h3 id="Access-Control-Allow-Credentials">Access-Control-Allow-Credentials</h3>
-
-<p>{{HTTPHeader("Access-Control-Allow-Credentials")}} 头指定了当浏览器的<code>credentials</code>设置为true时是否允许浏览器读取response的内容。当用在对preflight预检测请求的响应中时,它指定了实际的请求是否可以使用<code>credentials</code>。请注意:简单 GET 请求不会被预检;如果对此类请求的响应中不包含该字段,这个响应将被忽略掉,并且浏览器也不会将相应内容返回给网页。</p>
-
-<pre>Access-Control-Allow-Credentials: true
-</pre>
-
-<p>上文已经讨论了<a href="#Requests_with_credentials">附带身份凭证的请求</a>。</p>
-
-<h3 id="Access-Control-Allow-Methods">Access-Control-Allow-Methods</h3>
-
-<p>{{HTTPHeader("Access-Control-Allow-Methods")}} 首部字段用于预检请求的响应。其指明了实际请求所允许使用的 HTTP 方法。</p>
-
-<pre>Access-Control-Allow-Methods: &lt;method&gt;[, &lt;method&gt;]*
-</pre>
-
-<p>相关示例见<a href="https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Access_control_CORS$edit#Preflighted_requests">这里</a>。</p>
-
-<h3 id="Access-Control-Allow-Headers">Access-Control-Allow-Headers</h3>
-
-<p>{{HTTPHeader("Access-Control-Allow-Headers")}} 首部字段用于预检请求的响应。其指明了实际请求中允许携带的首部字段。</p>
-
-<pre>Access-Control-Allow-Headers: &lt;field-name&gt;[, &lt;field-name&gt;]*
-</pre>
-
-<h2 id="HTTP_请求首部字段">HTTP 请求首部字段</h2>
-
-<p>本节列出了可用于发起跨域请求的首部字段。请注意,这些首部字段无须手动设置。 当开发者使用 XMLHttpRequest 对象发起跨域请求时,它们已经被设置就绪。</p>
-
-<h3 id="Origin">Origin</h3>
-
-<p>{{HTTPHeader("Origin")}} 首部字段表明预检请求或实际请求的源站。</p>
-
-<pre>Origin: &lt;origin&gt;
-</pre>
-
-<p>origin 参数的值为源站 URI。它不包含任何路径信息,只是服务器名称。</p>
-
-<div class="note"><strong>Note:</strong> 有时候将该字段的值设置为空字符串是有用的,例如,当源站是一个 data URL 时。</div>
-
-<p>注意,不管是否为跨域请求,ORIGIN 字段总是被发送。</p>
-
-<h3 id="Access-Control-Request-Method">Access-Control-Request-Method</h3>
-
-<p>{{HTTPHeader("Access-Control-Request-Method")}} 首部字段用于预检请求。其作用是,将实际请求所使用的 HTTP 方法告诉服务器。</p>
-
-<pre>Access-Control-Request-Method: &lt;method&gt;
-</pre>
-
-<p>相关示例见<a href="#Preflighted_requests">这里</a>。</p>
-
-<h3 id="Access-Control-Request-Headers">Access-Control-Request-Headers</h3>
-
-<p>{{HTTPHeader("Access-Control-Request-Headers")}} 首部字段用于预检请求。其作用是,将实际请求所携带的首部字段告诉服务器。</p>
-
-<pre>Access-Control-Request-Headers: &lt;field-name&gt;[, &lt;field-name&gt;]*
-</pre>
-
-<p>相关示例见<a href="#">这里</a>。</p>
-
-<h2 id="规范">规范</h2>
-
-<table>
- <tbody>
- <tr>
- <th scope="col">Specification</th>
- <th scope="col">Status</th>
- <th scope="col">Comment</th>
- </tr>
- <tr>
- <td>{{SpecName('Fetch', '#cors-protocol', 'CORS')}}</td>
- <td>{{Spec2('Fetch')}}</td>
- <td>New definition; supplants CORS specification.</td>
- </tr>
- <tr>
- <td>{{SpecName('CORS')}}</td>
- <td>{{Spec2('CORS')}}</td>
- <td>Initial definition.</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.headers.Access-Control-Allow-Origin")}}</p>
-
-<h3 id="注">注</h3>
-
-<ul>
- <li>IE 10 提供了对规范的完整支持,但在较早版本(8 和 9)中,CORS 机制是借由 XDomainRequest 对象完成的。</li>
- <li>Firefox 3.5 引入了对 XMLHttpRequests 和 Web 字体的跨域支持(但最初的实现并不完整,这在后续版本中得到完善);Firefox 7 引入了对 WebGL 贴图的跨域支持;Firefox 9 引入了对 drawImage 的跨域支持。</li>
-</ul>
-
-<h2 id="参见">参见</h2>
-
-<ul>
- <li><a href="http://arunranga.com/examples/access-control/">Code Samples Showing <code>XMLHttpRequest</code> and Cross-Origin Resource Sharing</a></li>
- <li><a href="/en-US/docs/Web/HTTP/Server-Side_Access_Control">Cross-Origin Resource Sharing From a Server-Side Perspective (PHP, etc.)</a></li>
- <li><a href="http://www.w3.org/TR/cors/">Cross-Origin Resource Sharing specification</a></li>
- <li>{{domxref("XMLHttpRequest")}}</li>
- <li><a href="/en-US/docs/Web/API/Fetch_API">Fetch API</a></li>
- <li><a href="http://www.kendoui.com/blogs/teamblog/posts/11-10-03/using_cors_with_all_modern_browsers.aspx">Using CORS with All (Modern) Browsers</a></li>
- <li><a href="http://www.html5rocks.com/en/tutorials/cors/">Using CORS - HTML5 Rocks</a></li>
-</ul>
-
-<p>{{ languages( { "ja": "ja/HTTP_access_control" } ) }}</p>