首页 > 解决方案 > 被 CORS 政策阻止

问题描述

 export const getMovies = (text) => async (dispatch) => {
 
  try {
    const res = await axios.get(
      `https://api.themoviedb.org/4/search/movie?api_key=${process.env.REACT_APP_API_KEY}&language=en-us&page=1&include_adult&query=${text}` );
  
    dispatch({
      type: GET_MOVIES,
      payload: res.data,
    });
  } catch (err) {
    console.error(err);
  }
};

在我的 REACT/REDUX 项目中运行这行代码时遇到以下错误:

 Access to XMLHttpRequest at 'https://api.themoviedb.org/4/search/movie?api_key=b1d71b9e30e9e87132c7a808864f227c&language=en-us&page=1&include_adult&query=' 
from origin 'http://localhost:3000' has been blocked by CORS policy: Request header field auth-token is not 
allowed by Access-Control-Allow-Headers in preflight response.

任何解决此错误的意见将不胜感激。

标签: reactjsapireduxaxios

解决方案


推荐阅读