【发布时间】:2021-05-29 12:11:50
【问题描述】:
我正在使用 react-native 移动应用程序中的以下代码对 dj-rest-auth 本地链接进行社交身份验证调用。但是我总是收到一个错误。请让我知道是什么问题。
fetch(
"http://localhost:8000/dj-rest-auth/facebook/",
{
method: "POST",
headers: {
'Accept': 'application/json',
'Content-type':'application/json'
},
xsrfCookieName:"csrftoken",
xsrfHeaderName:'X-CSRFToken',
body:JSON.stringify({access_token : resolvedToken})
}
)
.then(resp => resp.json())
.then(data => {
console.log(data);
}
)
.catch(error => console.log(error))
错误详情:
Network request failed
at node_modules/whatwg-fetch/dist/fetch.umd.js:535:17 in setTimeout$argument_0
at [native code]:null in callFunctionReturnFlushedQueue
替代错误更新: 如果我将 axios 用于 API 请求而不是 fetch,即 await axios.post 而不是 fetch,那么我会收到以下错误:
Network Error
at node_modules/axios/lib/core/createError.js:16:14 in createError
at node_modules/axios/lib/adapters/xhr.js:84:24 in handleError
at node_modules/react-native/Libraries/Network/XMLHttpRequest.js:600:10 in setReadyState
at node_modules/react-native/Libraries/Network/XMLHttpRequest.js:395:6 in __didCompleteResponse
at node_modules/react-native/Libraries/vendor/emitter/EventEmitter.js:189:10 in emit
at [native code]:null in callFunctionReturnFlushedQueue
【问题讨论】:
-
“但是我总是收到错误” 错误是什么?我们需要更多详细信息来帮助您解决问题。请更新您的问题。
-
能否提供错误详情
-
如果我记录数据,则显示未定义。
-
console.log(error)怎么样? -
更新了错误详情
标签: javascript react-native fetch-api django-rest-auth