
此问题通常与后端服务器有关,但是如果您无权访问服务器,则有两种选择
*使用此chrome扩展程序的 *第一个选项 :Allow-Control-Allow-
Origin,但是很遗憾,此扩展程序在其他浏览器中不可用,因此您需要使用
*使用在线CORS代理的 *第二种选择
https://cors-anywhere.herokuapp.com/http://example.com
http://cors-
proxy.htmldriven.com/?url=http://www.htmldriven.com/sample.json
对于需要绕过与执行对第三方服务的标准AJAX请求有关的同源策略的开发人员,CORS代理是一项免费服务。
这是使用CORS代理进行Axiox呼叫的示例
const urlProxy = 'https://cors-anywhere.herokuapp.com/http://example.com';export function post() { let users = { username: '', password: '', }; return axios({ method:'POST', url:urlProxy, data: users, // Delete it if you dont have a data withCredentials: true, // Delete it if your request doesn't required credentials headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' 'Origin': '*', 'Access-Control-Allow-Headers': '*', 'Access-Control-Allow-Origin': '*', } }) .then(function (response) { console.log(response); }) .catch(function (error) { console.log(error); })}我添加了
withCredentials()它,使您的浏览器在XHR请求中包含cookie和身份验证标头。如果您的服务依赖于任何cookie(包括会话cookie),则仅在使用此选项集的情况下才能使用。
有一个 Firefox的 扩展,增加了CORS头到3月5日发布的(编译36.0.1),任何HTTP响应在最新的Firefox工作2015年入住此链接
希望这个能对您有所帮助
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)