javascript - 在 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 错误告终。请帮帮我。
解决方案
推荐阅读
- python - 多个索引与python中的for循环匹配
- r - 数据框的总和列
- bash - 用于启动客户端和服务器开发环境的 Bash 脚本
- html - 调整窗口大小时如何反转div的堆叠方式?
- java - 为什么我的 Connect 4 程序中出现 NullPointerException?
- javascript - 如何定义名为 SOMETHING.something 的类?
- python-3.x - 如何在 docker 容器中使用 selenium 设置 python 应用程序
- caching - 如何清除 solcache 中的所有条目并从 solcache 中删除一个条目(键)
- c++ - 插入新元素时结束迭代器是否会更新?
- ios - 无法在表中插入行“尝试将第 0 行插入第 0 节,但更新后只有 0 节”