?
本文檔使用 php中文網手冊 發(fā)布
Access-Control-Allow-Credentials
響應報頭指示的請求的響應是否可以暴露于該頁面。當true
值返回時它可以被暴露。
憑證是 Cookie ,授權標頭或 TLS 客戶端證書。
當作為對預檢請求的響應的一部分使用時,它指示是否可以使用憑證進行實際請求。請注意,簡單的GET
請求不是預檢的,所以如果請求使用憑證的資源,如果此資源不與資源一起返回,瀏覽器將忽略該響應,并且不會返回到 Web 內容。
Access-Control-Allow-Credentials
的 header 文件與該XMLHttpRequest.withCredentials
屬性或者在提取 API credentials
的Request()
構造函數中的選項一起工作。必須在雙方(Access-Control-Allow-Credentials
的 header 和 XHR 或 Fetch 請求中)設置證書,以使 CORS 請求憑證成功。
Header type | Response header |
---|---|
Forbidden header name | no |
Access-Control-Allow-Credentials: true
trueThe only valid value for this header is true
(case-sensitive). If you don't need credentials, omit this header entirely (rather than setting its value to false
).
允許憑證:
Access-Control-Allow-Credentials: true
使用 XHR 憑證:
var xhr = new XMLHttpRequest();xhr.open('GET', 'http://example.com/', true); xhr.withCredentials = true; xhr.send(null);
使用提取憑證:
fetch(url, { credentials: 'include' })
Specification | Status | Comment |
---|---|---|
FetchThe definition of 'Access-Control-Allow-Credentials' in that specification. | Living Standard | Initial definition |
Feature | Chrome | Firefox | Edge | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|---|
Basic Support | 4 | 3.5 | 12 | 10 | 12 | 4 |
Feature | Android | Chrome for Android | Edge mobile | Firefox for Android | IE mobile | Opera Android | iOS Safari |
---|---|---|---|---|---|---|---|
Basic Support | 2.1 | (Yes) | (Yes) | 1.0 | (Yes) | 12 | 3.2 |