![](/img/trans.png)
[英]FastAPI: React native frontend giving 422 error during auth flow
[英]React Native and FastAPI issue
我在創建 React Native 應用程序時遇到了一個問題。 我在后端使用 FastAPI。 在向我的后端發出此調用時,沒有任何反應。
function sendAkt() {
fetch("https://192.168.1.5:8000/newActivity", {
method: "POST",
headers: {
'Accept': "application/json",
"Content-Type": "application/json",
},
body: JSON.stringify({
name: ime,
desc: opis,
place: mjesto,
team: tim,
typeOf: pickerSel,
id: users.id,
}),
})
.then(_=> console.log('rea for the minute'))
.catch(e => console.log(e))
}
沒有錯誤,后端的控制台從來沒有報告過對后端路由的調用。 似乎獲取只是掛起。 因為大約 3 分鍾后,這會在控制台中彈出
Network request failed
- node_modules\whatwg-fetch\dist\fetch.umd.js:505:17 in setTimeout$argument_0
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:135:14 in _callTimer
- node_modules\react-native\Libraries\Core\Timers\JSTimers.js:387:16 in callTimers
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:425:19 in __callFunction
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:112:6 in __guard$argument_0
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:373:10 in __guard
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:111:4 in callFunctionReturnFlushedQueue
* [native code]:null in callFunctionReturnFlushedQueue
這是我正在調用的后端路由
@app.post('/newActivity')
async def unos(request: NewActivity):
print('route Reaches')
# name = request.name
# desc = request.desc
# place = request.place
# team = request.team
# typeOf = request.typeOf
# id = request.id
# year = 10
# new_activity = Activities(activity_type_id=typeOf, academic_year_id=year,
# description=desc,
# user_id=id, team_id=team, title=name, location=place)
# session.add(new_activity)
# session.commit()
return JSONResponse(content='Uspijeh')
這是我后端的 CORS 設置
app.add_middleware(
CORSMiddleware,
allow_origins=['http://localhost:19001'],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
我已經在這里待了幾個小時,我不知道它可能是什么導致了這個問題
真傻的問題。 我正在使用https
而不是http. Changing to
調用本地服務器http. Changing to
http. Changing to
http` 修復了它
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.