Reactjs 访问';我的url';来自原点';http://www.mywebsite.com' 已被CORS策略阻止

Reactjs 访问';我的url';来自原点';http://www.mywebsite.com' 已被CORS策略阻止,reactjs,Reactjs,我得到的cors政策错误如下 Access to fetch at 'my-url' from origin 'http://www.mywebsite.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the reques

我得到的cors政策错误如下

Access to fetch at 'my-url' from origin 'http://www.mywebsite.com' has been blocked by CORS policy: 
No 'Access-Control-Allow-Origin' header is present on the requested resource. 
If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
这是我的代码:

const requestOptionsBR = {
        method: "POST",
        headers: new Headers({
            "Content-Type": "application/json",
            "Access-Control-Allow-Origin": "*",
            "Access-Control-Allow-Methods": "OPTIONS,POST,GET"
        }),
        body: JSON.stringify({
            action: "user_reports",
            user_id: this.state.user_id,
            start_date: this.convertDate(this.state.startDate),
            end_date: this.convertDate(this.state.endDate),
        }),
    };


    fetch(my-url, requestOptionsBR)
        .then((res) => res.json())
        .then((data) => {
            this.setState({ loadingStatus: true });
            console.log("User Reports", data)
            if (data.status) {
                this.setState({
                    user_data: data.params,
                    loadingStatus: false,
                    resultRetrieved: true,
                });
                this.generate_download_csv_data(data.params);
            }
上述方法在本地运行良好,但在生产中不起作用。 如何克服这个问题?
任何帮助都很好。

不允许使用通配符
*
,因为出于安全原因,您必须提供特定的协议、域和端口

更多信息请点击这里

如错误消息所示,您还可以设置选项:

mode: 'no-cors'
…在您的
请求选项br
中,但是这将限制您可以在请求标题中输入的内容

更多信息请点击这里


我尝试过的两种解决方案都不起作用