在移动请求上获取axios的问题

时间:2020-04-10 22:42:22

标签: node.js reactjs axios

我正在尝试通过对节点api的响应发出axios.post请求。 在我的PC或Mac上,它运行良好,但是在我的iPhone Chrome或Safari中,效果不佳。

代码:

    const transport = axios.create({
    origin: "http://localhost:3003",
    headers: {
        'Access-Control-Allow-Origin': '*',
        'Content-Type': 'application/json',
    },
    withCredentials: true,
})

;

transport.post('http://localhost:3001/user/signin', user) 
    .then(res => {
        if(res.status === 200) {
            Cookies.set('user', res.data.token, { expires: 7 });
            const user = {
                fullName: res.data.user.full_name,
                email: res.data.user.email,
                token: res.data.token
            };
            props.signIn(user);
            history.push('/');
        }
    })
    .catch(err => {
        props.clearPropsFromUser();
    });

有人可以帮助我吗?谢谢

0 个答案:

没有答案