为了账号安全,请及时绑定邮箱和手机立即绑定

React Native 和 FastAPI 问题

React Native 和 FastAPI 问题

斯蒂芬大帝 2023-08-22 18:36:21
我在创建 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 设置
查看完整描述

1 回答

?
阿晨1998

TA贡献2037条经验 获得超6个赞

真是愚蠢的问题。我正在调用本地服务器而https不是http. Changing to http` 修复了它



查看完整回答
反对 回复 2023-08-22
  • 1 回答
  • 0 关注
  • 102 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信