开发者社区> 问答> 正文

【OSS】OSS跨域资源共享(CORS)错误排除

浏览器报403错误,具体如下:

OPTIONS http://bucket.oss-cn-beijing.aliyuncs.com/
XMLHttpRequest cannot load http://bucket.oss-cn-beijing.aliyuncs.com/. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin '{yourwebsiet}' is therefore not allowed access. The response had HTTP status code 403.

OSS报CORS请求不允许的错误,具体如下:

<Code>AccessForbidden</Code>
<Message>CORSResponse: This CORS request is not allowed. This is usually because the evaluation of Origin, request method / Access-Control-Request-Method or Access-Control-Requet-Headers are not whitelisted by the resource's CORS spec.</Message>

展开
收起
hd4q62obg7msi 2021-11-17 19:43:03 5060 0
1 条回答
写回答
取消 提交回答
  • 可能原因

    跨域规则配置错误。

    • CORS报错一般是站点类应用导致,浏览器中可以查看请求详情。例如Chrome,按F12打开开发者工具 ,在Network页签中查看相应元素。

    • OSS返回的错误可以通过抓包获取。如果使用Wireshark,筛选器可以指定为host bucket-name.oss-cn-beijing.aliyuncs.com。

    解决方法

    按照以下步骤正确配置跨域规则。

    1. 登录OSS管理控制台,选择目标Bucket,然后选择权限管理 > 跨域设置。

    2. 在跨域规则配置页面,设置以下参数: 来源(AllowedOrigin):设置为*。 允许Methods:选中全部选项(GET、PUT、DELETE、POST、HEAD)。 允许Headers:设置为*。 暴露Headers:设置为指定值或者不填。

    2021-11-18 15:45:53
    赞同 展开评论 打赏
来源圈子
更多
收录在圈子:
问答排行榜
最热
最新

相关电子书

更多
OSS运维进阶实战手册 立即下载
《OSS运维基础实战手册》 立即下载
OSS运维基础实战手册 立即下载