aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/request/credentials/index.html
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/api/request/credentials/index.html
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/api/request/credentials/index.html')
-rw-r--r--files/zh-cn/web/api/request/credentials/index.html64
1 files changed, 64 insertions, 0 deletions
diff --git a/files/zh-cn/web/api/request/credentials/index.html b/files/zh-cn/web/api/request/credentials/index.html
new file mode 100644
index 0000000000..f7a57ad6c0
--- /dev/null
+++ b/files/zh-cn/web/api/request/credentials/index.html
@@ -0,0 +1,64 @@
+---
+title: Request.credentials
+slug: Web/API/Request/credentials
+tags:
+ - API
+ - Fetch
+ - 属性
+ - 证书
+ - 请求
+translation_of: Web/API/Request/credentials
+---
+<div>{{APIRef("Fetch")}}</div>
+
+<p><strong><code>credentials</code></strong> 是{{domxref("Request")}}接口的只读属性,用于表示用户代理是否应该在跨域请求的情况下从其他域发送cookies。这与XHR的withCredentials 标志相似,不同的是有三个可选值(后者是两个):</p>
+
+<ul>
+ <li><code>omit</code>: 从不发送cookies.</li>
+ <li><code>same-origin</code>: 只有当URL与响应脚本同源才发送 cookies、 HTTP Basic authentication 等验证信息.(浏览器默认值,在旧版本浏览器,例如safari 11依旧是omit,safari 12已更改)</li>
+ <li><code>include</code>: 不论是不是跨域的请求,总是发送请求资源域在本地的 cookies、 HTTP Basic authentication 等验证信息.</li>
+</ul>
+
+<h2 id="语法">语法</h2>
+
+<pre class="brush: js">var myCred = request.credentials;</pre>
+
+<h3 id="Value">Value</h3>
+
+<p>A {{domxref("RequestCredentials")}} value.</p>
+
+<h2 id="举例">举例</h2>
+
+<p>在以下代码中,我们使用{{domxref("Request.Request()")}}创建了一个新的request(为了一个与脚本在同一目录下的图片文件), 接着将request credentials存入一个变量:</p>
+
+<pre class="brush: js">var myRequest = new Request('flowers.jpg');
+var myCred = myRequest.credentials; // returns "same-origin" by default</pre>
+
+<h2 id="说明">说明</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Fetch','#dom-request-credentials','credentials')}}</td>
+ <td>{{Spec2('Fetch')}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="浏览器兼容性">浏览器兼容性</h2>
+
+<p>{{Compat("api.Request.credentials")}}</p>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/API/ServiceWorker_API">ServiceWorker API</a></li>
+ <li><a href="/en-US/docs/Web/HTTP/Access_control_CORS">HTTP access control (CORS)</a></li>
+ <li><a href="/en-US/docs/Web/HTTP">HTTP</a></li>
+</ul>