reactjs - 以外部 api 为前缀的任何地方的 CORS 都需要 400 标头
问题描述
我正在使用 React 并希望显示来自外部 api 的图像,并在该 api 前面加上 CORS 任何 url。但我收到此错误消息:
GET https://cors-anywhere.herokuapp.com/https://api.fortnox.se/3/archive/8c05c536-c110-402d-82da-60f25f6b0e1c 400 (Header required)
我一直在寻找解决方案,但我只找到有关如何在服务器端解决此问题的解决方案。但由于这是一个外部 api,我不能这样做。有什么解决办法吗?
这是我的代码:
export const SingleProductImage = (props) => {
const [articleImg, setArticleImg] = useState('')
console.log(articleImg)
console.log(props.fileid)
useEffect(() => {
fetch(`https://cors-anywhere.herokuapp.com/https://api.fortnox.se/3/archive/${props.fileid}`, {
method: 'GET',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
'Access-Token': accessToken,
'Client-Secret': clientSecret,
}
})
.then((res) => {
setArticleImg(res.url)
})
.catch((err) => console.log(err))
}, [props.fileid])
return (
<div>
<img src={articleImg} alt="product" className="img" />
</div>
)
}
谢谢!!
解决方案
您尝试代理的 URL 目前似乎无法通过 cors-anywhere.herokuapp.com 访问
推荐阅读
- c# - 在其他类中操作后返回一个变量
- asp.net - 如何调用 Angular-CLI .NET Core 中的 index.html?
- asp.net-mvc - phpMyAdmin 上的连接被拒绝
- apache-spark - hbase-spark 连接器可以用于按性能良好的列对 hbase 行进行排序吗?
- asp.net-mvc - 如何在 mvc 视图中显示来自数据库的锚标记
- postgresql - 没有时区的时间戳 >= bytea
- python - Udacity python 代码测验
- sql - 查询与 Hive QL 中另一列中的每个值关联的最短字符串值的更有效方法
- spring - Spring 4.3如何从缓存中解包一个可选的,如果它是空的
- c++ - 如何在不知道 Arduino 大小的情况下创建数组并在其中存储值