hyp*_*rdo 7 javascript amazon-s3 amazon-web-services cors
尝试从Amazon S3服务器加载图像(将crossorigin设置为匿名)后,我们仍然遇到可怕的错误:
XMLHttpRequest cannot load
http://resource-url No
'Access-Control-Allow-Origin' header is present on the requested resource. Origin
'http://server-url' is therefore not allowed access.
Run Code Online (Sandbox Code Playgroud)
我们已经尝试了几种CORS配置,例如
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)
以及Amazon的默认CORS配置。仍然,同样的错误。
其他一些注意事项:
curl -XGET -H 'Origin: anonymous' http://resource-url 返回看起来像是图像,从 ?PNG我尽力了,因此,不胜感激。非常感谢!
可能添加<AllowedMethod>HEAD</AllowedMethod>:
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>HEAD</AllowedMethod>
<MaxAgeSeconds>3000</MaxAgeSeconds>
<AllowedHeader>*</AllowedHeader>
</CORSRule>
</CORSConfiguration>
Run Code Online (Sandbox Code Playgroud)
似乎有一些现代浏览器使用该HEAD方法发送的飞行前检查(用于服务器负载检查)。更多阅读在这里和这里。
| 归档时间: |
|
| 查看次数: |
4199 次 |
| 最近记录: |