首页 > 解决方案 > 在 Vue 中通过 AXIOS 发布请求总是返回 405 和 CORS 错误

问题描述

我知道这个错误有多种解决方案,老实说,我已经尝试了所有解决方案,但它根本不起作用。我正在构建一个 Vue 应用程序,我正在 loclahost 中测试它以通过单击按钮发送 SMS。下面是代码;

            const headers = {
            headers: {
              "content-type": "application/json",
              "Access-control-allow-origin": "*",
              authorization: basicAuthHeader(username, upassword),
              "account-id": Buffer.from(acc_id, "utf8").toString("base64"),
            },
          };

          function basicAuthHeader(uname, upass) {
            let base64String = Buffer.from(
              `${uname}:${upass}`,
              "utf8"
            ).toString("base64");
            return `Basic ${base64String}`;
          }
          axios
            .post(
              `https://www.echomobile.org/api/messaging/send?phone=${phone}&message=${message}`,

              headers
            )
            .then((res) => console.log(res))
            .catch((err) => console.error(err));


我被卡住的另一个原因是缺乏文档。无论我做什么,我总是以 CORS 和 405 错误告终。请帮帮我。

标签: javascriptvue.jspostaxioscors

解决方案


推荐阅读