我没有发出任何不安全的请求,而是通过https调用了一个API,但是在chrome dev工具的网络标签中以某种方式出现了一个Http请求,但我不是通过相同的API发出的
我搜索了整个项目,所有协议都是Https。
https://i.imgur.com/9A7leKM.png
https://i.imgur.com/JfgzS1v.png
实际要求
export const getPGCR = instanceId => {
return axios.get(
`https://www.bungie.net/Platform/Destiny2/Stats/PostGameCarnageReport/${instanceId}/`,
{
headers: {
"X-API-KEY": process.env.REACT_APP_API_KEY
}
}
);
};
import React, { Component } from "react";
import { getPGCR } from "../utility/endpoints";
import Loading from "../components/Loading";
import { connect } from "react-redux";
class PGCR extends Component {
state = {
pgcr: "",
loading: true,
activityNotFound: false
};
async componentDidMount() {
try {
const instanceId = parseInt(this.props.match.params.instanceId);
const pgcrResult = await getPGCR(instanceId);
this.setState({ pgcr: pgcrResult.data.Response }, () => {
this.setState({ loading: false });
});
} catch (err) {
if (err.response.data.ErrorCode === 1653) {
this.setState({ loading: false, activityNotFound: true });
} else if (err.response.data.ErrorCode === 5) {
this.props.failGetData();
}
}
}
render() {
if (!this.state.loading) {
if (!this.state.activityNotFound) {
return (
<div className="infamy-container">
<div className="track-wrapper">
{this.state.pgcr.entries.map((entry, index) => {
const player = {
name: entry.player.destinyUserInfo.displayName,
icon: `https://www.bungie.net${
entry.player.destinyUserInfo.iconPath
}`,
completed: entry.values.completed.basic.displayValue,
kills: entry.values.kills.basic.displayValue,
deaths: entry.values.deaths.basic.displayValue
};
return (
<div key={index} className="track-container">
<div
className="track-container--effect track-container--effect_pgcr"
style={{
backgroundImage: `url(${player.icon})`
}}
/>
<div className="track-container--content">
<div>
<h4>{player.name}</h4>
</div>
<ul className="center-ul">
<li>Kills: {player.kills}</li>
<li>Deaths: {player.deaths}</li>
<li>Completed: {player.completed}</li>
</ul>
</div>
</div>
);
})}
</div>
</div>
);
} else {
return (
<div className="infamy-container">
<div className="error_activity">Activity Not Found</div>
</div>
);
}
} else {
return (
<div className="infamy-container">
<Loading />;
</div>
);
}
}
}
const mapStoreToProps = store => {
return {
player: store.player
};
};
export const failGetData = () => {
return dispatch => {
return new Promise(async (resolve, reject) => {
dispatch({
type: "FAIL_SET_DATA",
payload: "Bungie API is down at this moment, please try again later"
});
resolve();
});
};
};
export default connect(
mapStoreToProps,
{ failGetData }
)(PGCR);
答案 0 :(得分:0)
问题是该API具有301重定向,该重定向错误地重定向到了HTTP协议并导致应用程序中断。 他们确认这是github上的错误