简体   繁体   English

无法获取刷新令牌(React.js)

[英]Fetch for refresh token not working (React.js)

Here I am again. 我又来了 I'm trying to do a fetch to ask the API for a refreshed token based on previous stored token in localStorage. 我正在尝试执行提取操作,以根据以前在localStorage中存储的令牌向API索要刷新的令牌。 It gives error 400() and I still don't know why. 它给出了错误400(),我仍然不知道为什么。 It is required for the previous token to go on the body of the POST request. 前一个令牌必须位于POST请求的正文中。

Any help is acceptable, I feel really lost... I've been with this issue for days already... 任何帮助都是可以接受的,我真的很失落。。。

    fetch(url + '/api-token-refresh/', {
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        }, body: JSON.stringify({
            token: localStorage.getItem('token')
        })
    })

I think the problem comes from when I store in localStorage, because on the Request Payload I get token: "{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo0LCJ1c2VybmFtZSI6InJpY2FyZG8uY2Fycm9sYUBnbWFpbC5jb20iLCJleHAiOjE1MzMxMTY2OTQsImVtYWlsIjoicmljYXJkby5jYXJyb2xhQGdtYWlsLmNvbSIsIm9yaWdfaWF0IjoxNTMyNTExODk0fQ.sS3kuC8o51Rix505BFy9nT5w9iygNaKViGq_fVtVChk"}" what means I don't get just the token... 我认为,问题的来源,当我存储在localStorage的,因为在请求负载,我得到token: "{"token":"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjo0LCJ1c2VybmFtZSI6InJpY2FyZG8uY2Fycm9sYUBnbWFpbC5jb20iLCJleHAiOjE1MzMxMTY2OTQsImVtYWlsIjoicmljYXJkby5jYXJyb2xhQGdtYWlsLmNvbSIsIm9yaWdfaWF0IjoxNTMyNTExODk0fQ.sS3kuC8o51Rix505BFy9nT5w9iygNaKViGq_fVtVChk"}"是什么意思我不明白只是令牌...

If you need anything else, just ask and I will add to the question. 如果您还需要其他任何内容,请问我,我将补充这个问题。 Thank you for your attention. 感谢您的关注。

I was using JSON.stringify and the token was going on the Request has a string, has soon has I changed the body, the status changed to 200. Thanks for who helped! 我使用的是JSON.stringify,令牌上的Request字符串,不久后我更改了正文,状态更改为200。感谢谁的帮助!

fetch(url + '/api-token-refresh/', {
    method: 'POST',
    headers: {
        'Content-Type': 'application/json',
        'Accept': 'application/json'
    }, body: (localStorage.getItem('token'))
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM