IE发送“接受”标头,但CORS不允许这样做

时间:2018-08-08 07:40:40

标签: angular amazon-s3 cors angular-httpclient

下一段代码用于将文件从angular上载到S3(使用HttpClient):

    const form = new FormData();
    form.append('file', item.file, item.file.name);

    let headers = new HttpHeaders()
        .set('x-amz-server-side-encryption', 'AES256')
        .set('Cache-Control', 'max-age=31536000')
        .set('Content-Type', item.file.type);

    const req = new HttpRequest('PUT', link, form, {
        reportProgress: true,
        headers: headers
    });

    let request = this.httpClient.request(req);

它在Chrome中工作正常,但是在IE中,它会自动将Accept标头添加到Access-Control-Request-Headers中,但这是CORS配置所不允许的。

可以更新CORS配置,但是有什么方法可以在前端修复它?

当没有“接受”作为允许的标头时,我在预检请求中收到消息CORSResponse: This CORS request is not allowed. This is usually because the evalution of Origin, request method / Access-Control-Request-Method or Access-Control-Request-Headers are not whitelisted by the resource's CORS spec,收到403。当我只发送带有/不带有Accept标头时,它可以正常工作,但是当它添加到Access-Control-Request-Headers中时-上面的消息失败。

0 个答案:

没有答案