Access-Control-Allow-Origin 响应头指定了该响应的资源是否被允许与给定的origin共享。| Header type | Response header |
|---|---|
| Forbidden header name | no |
语法
Access-Control-Allow-Origin: * Access-Control-Allow-Origin: <origin>
指令
- *
- 对于不需具备凭证(credentials)的请求,服务器会以“
*”作为通配符,从而允许所有域都具有访问资源的权限。 - <origin>
- 指定一个可以访问资源的URI。
示例
如需允许所有资源都可以访问您的资源,您可以如此设置:
Access-Control-Allow-Origin: *
如需允许https://developer.mozilla.org访问您的资源,您可以设置:
Access-Control-Allow-Origin: https://developer.mozilla.org
CORS和缓存
如果服务器未使用“*”,而是指定了一个域,那么为了向客户端表明服务器的返回会根据Origin请求头而有所不同,必须在Vary响应头中包含Origin。
Access-Control-Allow-Origin: https://developer.mozilla.org Vary: Origin
规范
| 规范 | 状态 | 注释 |
|---|---|---|
| Fetch Access-Control-Allow-Origin |
Living Standard | 初始定义 |
浏览器兼容性
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
| Feature | Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | Servo |
|---|---|---|---|---|---|---|---|
| Access-Control-Allow-Origin | 4 | 12 | 3.5 | 10 | 12 | 4 | ? |
| Feature | Android | Chrome for Android | Edge Mobile | Firefox for Android | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
| Access-Control-Allow-Origin | 2.1 | (Yes) | (Yes) | 1.0 | (Yes) | 12 | 3.2 |