reactjs - 被 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.
任何解决此错误的意见将不胜感激。
解决方案
推荐阅读
- spring - Spring boot和Spring数据找不到bean entityMangerFactory
- path - 启动 Visual Studio Code 时如何临时修改路径
- asp.net - 更新按钮无法使用
- javascript - 如何使用条件进行对象解构?
- python - 熊猫只在组内添加两行
- python - Python Selenium Firefox - 如何启用无头模式作为类/对象的一部分?
- css - 是否有其他方法可以在 css 中选择这些节点
- python - Python写入文件错误的字符串
- python - 读取 json 对象并在 python 中从中创建 csv 字符串
- javascript - 收到 npm run protractor 配置文件的错误消息,该文件以前运行良好