我正在尝试设置一个基本的服务调用来设置我设置的模拟点。我正在与超级代理进行通话,并且出于某种原因在触发帖子时在控制台中出现此错误
XMLHttpRequest cannot load http://www.mocky.io/v2/mytestdata. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access.
我尝试设置Access-Control-Allow-Origin
标题,但我认为我误解了如何使用它。这是超级电话:
function post(url, formData) {
return new Promise((resolve, reject) => {
superagent.post(url)
.send(formData)
.set("Access-Control-Allow-Origin", "http://www.mocky.io")
.end((err, response) => {
if (err) {
displayErrorMessage(reject, "error posting", err);
} else {
resolve(response.body);
}
});
});
}
所以即使使用那个set头也无法正常工作。不确定我在这里做错了什么,欢迎任何建议,谢谢!