问题描述
我正在尝试从API获取数据。在命令行中可以使用CURL,但是我想在ReactJS中使用fetch()或axios来实现。我真的很努力,没有成功。
curl -i -X GET -u user:pass -H "Accept:application/json" "http://sample.api.net/list"
status 301 - moved permanently
Location: https://sample.api.net:443/list
在-i旁边带有L重定向我,一切正常。
curl -iL -X GET -u user:pass -H "Accept:application/json" "http://sample.api.net/list"
status 200 OK
It works
我尝试使用fetch和axios,但始终给我301 Moved并无法获取。我还需要授权。
fetch("http://sample.api.net/list",{
redirect: "follow",headers: {
Accept: "application/json",Authorization: "Basic fdfdgdfgfd",},})
.then((response) => console.log(response))
.catch((err) => console.log(err));
不起作用:(
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)