CORS request not working in Safari

后端 未结 13 1421
忘掉有多难
忘掉有多难 2020-11-27 06:04

I am making a CORS xhr request. This works fine in chrome, however when I run in safari I get an \'Can not load ---- access not allowed by Access-control-allow-origin\'.

相关标签:
13条回答
  • 2020-11-27 06:53

    I encountered the same error when making an XHR request against a file in Amazon S3. On Safari 7 it was failing. I know you're not using Amazon S3, but I thought I'd post in case this solution helped others.

    The problem was that Safari 7 set the Access-Control-Request-Headers header to "origin, x-requested-with", but my AWS CORS configuration only allowed "x-requested-with":

    <?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>Authorization</AllowedHeader>
            <AllowedHeader>x-requested-with</AllowedHeader>
        </CORSRule>
    </CORSConfiguration>
    

    I added "origin" as an allowed header and everything worked fine.

            <AllowedHeader>origin</AllowedHeader>
    

    Note: the AllowedOrigin of * is for development purposes only. See @andes comment below for more information.

    0 讨论(0)
提交回复
热议问题