【发布时间】:2022-09-30 19:55:35
【问题描述】:
我正在使用 Expo Client 进行开发,但无法发送登录 API 调用。
onSubmit 函数
const onSubmit = async (username, password)=>{
console.log(username);
console.log(password);
await axios.post(
\'https://backend.unknownchats.com/accounts/login/\',
{
username: username,
password: password,
},
{
headers: {
\'Content-Type\': \"application/json\",
\'Accept\': \"application/json\",
}
}
).then(res=>{
console.log(res.data);
if (res.data.status===\"success\"){
localStorage.setItem(\'username\',res.data.username);
localStorage.setItem(\'token\',res.data.token);
navigation.navigate(\'Settings\');
}else{
setError(res.data.error);
}
}).catch(err=>console.log(err));
}
我得到的错误
苏米特
97127516
网络错误 在 node_modules\\axios\\lib\\core\\createError.js:17:22 在 createError 在 node_modules\\axios\\lib\\adapters\\xhr.js:120:6 in handleError 在 EventTarget.prototype.dispatchEvent 中的 node_modules\\event-target-shim\\dist\\event-target-shim.js:818:20 在 setReadyState 中的 node_modules\\react-native\\Libraries\\Network\\XMLHttpRequest.js:609:10 在 __didCompleteResponse 中的 node_modules\\react-native\\Libraries\\Network\\XMLHttpRequest.js:396:6 在 node_modules\\react-native\\Libraries\\vendor\\emitter_EventEmitter.js:135:10 在 EventEmitter#emit 在 __callFunction 中的 node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:414:4 在 node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:113:6 in __guard$argument_0 在 __guard 中的 node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:365:10 在 node_modules\\react-native\\Libraries\\BatchedBridge\\MessageQueue.js:112:4 in callFunctionReturnFlushedQueue
标签: react-native axios