【发布时间】:2018-12-04 06:46:09
【问题描述】:
我想向 Cloudinary API 发出 HTTP 请求以获取我帐户中的图片。必要的 url 如下所示:
https://<<API KEY>>:<<API SECRET>>@api.cloudinary.com/v1_1/<<RESOURCE NAME>>/resources/image
当我从浏览器中点击这个 url 时,我得到了我正在寻找的东西,一个带有我所有图片的漂亮 JSON 对象。
但是当我从 React 组件中点击 url 时,
componentDidMount() {
this.props.fetchArt();
}
我收到以下错误:
TypeError: Failed to execute 'fetch' on 'Window': Request
cannot be constructed from a URL that includes credentials:
动作创建者的样子
export function fetchArt() {
const url = 'https://'+CLOUDINARY_KEY+':'+CLOUDINARY_SECRET+'@api.cloudinary.com/v1_1/prints20/resources/image';
const request = fetch(url).then(res => res.json())
return {
type: FETCH_ART,
payload: request
}
}
回购链接:https://github.com/PantherHawk/prints20-2018
提前一百万谢谢!
【问题讨论】:
-
如果这是一个 CLOUDINARY_SECRET,它应该是秘密的。不要把它放在你的前端代码中。您可能必须创建一个访问它的服务器。它还将解决您的 CORS 问题????
标签: reactjs http frontend cloudinary