Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/446.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当我登录系统时,authorized正在工作,但在我登录后,我运行了另一个请求,但它没有给我响应,原因是未经授权_Javascript_Reactjs_React Native_Fetch Api - Fatal编程技术网

Javascript 当我登录系统时,authorized正在工作,但在我登录后,我运行了另一个请求,但它没有给我响应,原因是未经授权

Javascript 当我登录系统时,authorized正在工作,但在我登录后,我运行了另一个请求,但它没有给我响应,原因是未经授权,javascript,reactjs,react-native,fetch-api,Javascript,Reactjs,React Native,Fetch Api,我将登录信息发布到我的服务器并获得授权,但是在我登录后,我通过另一个请求获得了客户机信息,它不起作用。我以为是关于饼干的,但不确定。如果是关于Cookie的,我如何获取Cookie并将其设置在“获取”客户端请求中 我已经厌倦了添加凭证:“include”和凭证的其他选项,但不起作用。我看到一个包是react native cookies,但我无法将它实现到我的函数中 这是我的登录请求: export const postUserLogin = (email, password) => ne

我将登录信息发布到我的服务器并获得授权,但是在我登录后,我通过另一个请求获得了客户机信息,它不起作用。我以为是关于饼干的,但不确定。如果是关于Cookie的,我如何获取Cookie并将其设置在“获取”客户端请求中

我已经厌倦了添加
凭证:“include”
和凭证的其他选项,但不起作用。我看到一个包是
react native cookies
,但我无法将它实现到我的函数中

这是我的登录请求:

export const postUserLogin = (email, password) => new Promise((resolve, reject) => {
    try {
        fetch('http://1xx.xx.xx.xx/login', {
            credentials: "include",
            method: 'POST',
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                email: email,
                password: password
            })
        })
            .then(res => {
                res.json()
                    .then(jres => {
                        resolve(jres);
                    }).catch(e => {
                        reject(e);
                    })
            }).catch(e => {
                reject(e);
            })
    }
    catch (e) {
        reject(e);
    }

})
export const getClient = () => new Promise((resolve, reject) => {
    try {

        fetch('http://1xx.xx.xx.xx/',  {
            credentials: "include",
            method: 'GET',
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',   
            },
        }).then(res => {
            console.log(res)
            res.json()
                .then(jres => {
                    resolve(jres);
                }).catch(e => {
                    reject(e);
                })
        }).catch(e => {
            reject(e);
        })
    }
    catch (e) {
        reject(e);
    }

})
这是我的getClient信息请求:

export const postUserLogin = (email, password) => new Promise((resolve, reject) => {
    try {
        fetch('http://1xx.xx.xx.xx/login', {
            credentials: "include",
            method: 'POST',
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({
                email: email,
                password: password
            })
        })
            .then(res => {
                res.json()
                    .then(jres => {
                        resolve(jres);
                    }).catch(e => {
                        reject(e);
                    })
            }).catch(e => {
                reject(e);
            })
    }
    catch (e) {
        reject(e);
    }

})
export const getClient = () => new Promise((resolve, reject) => {
    try {

        fetch('http://1xx.xx.xx.xx/',  {
            credentials: "include",
            method: 'GET',
            headers: {
                Accept: 'application/json',
                'Content-Type': 'application/json',   
            },
        }).then(res => {
            console.log(res)
            res.json()
                .then(jres => {
                    resolve(jres);
                }).catch(e => {
                    reject(e);
                })
        }).catch(e => {
            reject(e);
        })
    }
    catch (e) {
        reject(e);
    }

})

您可能需要在getClient()请求中发送授权的头,这会导致您发送未经授权的头。您应该在服务中检查所需的参数。您可能需要在getClient()请求中发送授权标头,这会导致您未经授权。您应该在服务中检查所需的参数