根据 CORS 印前检查响应中的标头“访问控制-允许-标头”,不允许使用“内容类型”

我正在尝试进行一个简单的邮寄呼叫,该呼叫会将数据发送到mailgrid,以便自动邮件将发送给所选人员。但是,由于我对进行API调用相对较新,因此有些事情我不理解。


这些是我在尝试拨打电话时遇到的错误:


根据 CORS 印前检查响应中的标头“访问控制-允许标头”,不允许使用标头“内容类型”



CORS 请求未成功


他是我的执行调用的函数:


const sendMail = () => {

        axios.post(`https://{{private_url}}/public/mail/{user_id}/{mail_id}`, {

            headers: {

                "Access-Control-Allow-Headers": "Content-Type",

            },

            data: {

                first_name: data.first_name,

                last_name: data.last_name,

                message: data.message,

                email: data.email,

            }

        })

            .then(response => {

                console.log(response);

                console.log(response.headers)

                close();

            })

            .catch(error => {

                console.log(error);

                console.log(error.headers)

            });;

    }

我在监督什么,或者我在哪里犯了错误?


茅侃侃
浏览 97回答 2
2回答

手掌心

您不正确地使用了标头对象。 是分开的。请像这样使用:content-typeheaders: {    "Access-Control-Allow-Headers": "*", // this will allow all CORS requests    "Access-Control-Allow-Methods": 'OPTIONS,POST,GET', // this states the allowed methods    "Content-Type": "application/json" // this shows the expected content type},

墨色风雨

正如在开发人员.mozilla 说:使用 CORS 的 HTTP 请求失败,因为 HTTP 连接在网络或协议级别失败。该错误与 CORS 没有直接关系,而是某种基本的网络错误。在许多情况下,它是由浏览器插件(例如广告拦截器或隐私保护程序)阻止请求或VPN插件更改请求来源引起的。如果有,您可以禁用它。服务器还可以阻止导致访问控制允许源错误的未知源。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript