【问题标题】:Fetch Status Code from restful webservice从 RESTful Web 服务获取状态码
【发布时间】:2020-02-06 04:45:54
【问题描述】:

我不能只从一个安静的网络服务中获取状态代码。 Web 服务只是响应 201 或 401。我对本机反应还很陌生,现在我卡了几个小时。

我在另一个组件中调用这个函数。我收到的响应总是 LOG {"_40": 0, "_55": null, "_65": 0, "_72": null}

export default class forgotPasswordCall extends Component {
    _forgotPassword = async (username, email) => {
        let bodyData = {
            'username': username,
            'email': email,
        }
        try {
            const response = await fetch('webserviceURL', {
                method: "POST",
                headers: {
                    'Content-Type': 'application/json',
                    Accept: 'application/json',

                },
                body: JSON.stringify(bodyData)
            })
            return response.status;
        }
        catch (error) {
            console.error(error);
        }


    }


}

我需要自己接收状态码。

【问题讨论】:

标签: rest react-native


【解决方案1】:

我强烈建议使用axios 而不是 fetch。你应该试试看!

【讨论】:

    猜你喜欢
    • 2015-06-14
    • 1970-01-01
    • 2017-08-03
    • 1970-01-01
    • 1970-01-01
    • 2018-03-02
    • 1970-01-01
    • 1970-01-01
    • 2011-03-31
    相关资源
    最近更新 更多