【发布时间】:2018-02-23 13:29:03
【问题描述】:
我在从用 Python 编写的数据库中获取数据时遇到了一些问题。我包含在组件中的代码是:
axios.get('http://192.168.122:8000/messenger_api/fb_fanpages/', {
headers: {
'authorization': 'Token 539dec',
'content-type': 'application/json'
}
}).then(resp => {
console.log(resp)
}).catch(err => {
console.log(err)
})
我收到的浏览器错误是
我在 youtube 上查看了大量文章并观看了教程,但是我找不到解决问题的方法。我认为它与我正在使用的堆栈有关 - 也许是因为 Meteor?我正在考虑的另一个选项是标题 - 我使用了错误的语法?但是,这不太可能,因为正如我所说,我检查了文档等。对我来说一切看起来都很好。我不仅确定 Meteor env 什么的。我还为 Chrome 安装了 CORS 扩展程序以排除此选项。提前感谢所有答案。
【问题讨论】:
-
小更新。当我使用 Insomia 时,我可以得到响应。我还在代码中添加了 withCredentials: true 现在错误是 XMLHttpRequest cannot load Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be the当请求的凭据模式为“包含”时,通配符“*”。因此,Origin 'localhost:3000' 不允许访问。 XMLHttpRequest 发起的请求的凭证模式由 withCredentials 属性控制。