【发布时间】:2019-08-23 03:52:54
【问题描述】:
我正在使用 Axios 在我的 React 组件中设置条带连接按钮。重定向后我不断收到此错误
Access to XMLHttpRequest at 'https://connect.stripe.com/oauth/token' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
Thankyou.js:40 Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:87)
我从 url 获取代码并使用 axios.Post 创建 curl 请求。这是我重定向 URL 中的代码
// Thankyou.js
export default class Thankyou extends Component {
constructor(props) {
super(props);
}
componentDidMount() {
const code = qs.parse(this.props.location.search, {
ignoreQueryPrefix: true
}).code;
const params = {
client_id: "*******************",
client_secret: "**********************",
grant_type: "authorization_code",
code: code
};
axios
.post(
"https://connect.stripe.com/oauth/token",
// apiBaseUrl,
{ params }
)
.then(function(response) {
console.log(response);
})
.catch(function(error) {
console.log(error);
});
console.log(code);
}
render() {
return (
<div>
<h2>Thank you for connecting with us!</h2>
</div>
);
}
}
【问题讨论】:
-
API 未启用 CORS,因此您不会在浏览器中公开凭据以供所有人查看。使用代理和条带化服务器端 sdk
标签: reactjs axios stripe-payments