CORS问题采用爱可信做出反应

时间:2019-01-30 21:34:56

标签: reactjs cors axios

因此,对于这个问题,我研究了Web并尝试了几乎所有的解决方案,这些问题是我使用yelps融合API使用COR的。我正在使用react但尝试使用axios调用此API。这是我的代码。

static YelpApiSearch(searchedCity, onSuccess, onError) {
const config = {
  Authorization: process.env.REACT_APP_KEY
  Origin: "https://vendors.test"
};
axios.defaults.headers.common["X-Requested-With"] = "XMLHttpRequest";
axios
  .get(`https://corsanywhere.herokuapp.com/https://api.yelp.com/v3/businesses/search?categories=foodtrucks&location=${searchedCity}`,
    {
      withCredentials: true,
      headers: config
    }
  )
  .then(onSuccess)
  .catch(onError); }

拒绝设置不安全的标头来源错误

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:1)

这本身不是CORS问题。错误消息告诉您问题出在哪里。

  

拒绝设置不安全的标头来源错误

您无法指定Origin标头。它由浏览器确定。如果可以指定它,它将破坏CORS的大部分安全性。

config对象中删除指定它的尝试。