【问题标题】:How to ressolve TypeError: Network Request Failed for react project running at android device如何解决 TypeError: Network Request Failed for react project running at android device
【发布时间】:2021-07-22 14:33:56
【问题描述】:

在使用 expo 在 android 设备上运行我的 react 本机应用程序时,api 响应没有出现,这是使用 fetch 和 POST 方法完成的并收到此错误:

[未处理的承诺拒绝:TypeError:网络请求失败] 在 setTimeout$argument_0 中的 node_modules\whatwg-fetch\dist\fetch.umd.js:535:17 在 node_modules\react-native\Libraries\Core\Timers\JSTimers.js:130:14 在 _callTimer 在 node_modules\react-native\Libraries\Core\Timers\JSTimers.js:383:16 在 callTimers 在 __callFunction 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:416:4 在 __guard$argument_0 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:109:6 在 __guard 中的 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:364:10 在 node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:108:4 在 callFunctionReturnFlushedQueue at [native code]:null in callFunctionReturnFlushedQueue

【问题讨论】:

    标签: javascript android react-native fetch expo


    【解决方案1】:

    您介意分享您处理的 promise sn-p 以使用 FETCH API 获得响应吗?

    【讨论】:

    • async fetchesponse(){ var details = { 'APP_STUDY_ID': this.state.studyId, 'APP_PATIENT_DIARY_ID': this.state.diaryId, 'P_TOKEN': this.state.pToken }; var formBody = []; for (var property in details) { formBody.push(encodeURIComponent(details[key]) + "=" + encodeURIComponent(details[property])); } formBody = formBody.join("&");让 resp= await fetch(this.state.apiUrl, { method: 'POST', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: formBody }) }
    猜你喜欢
    • 2021-12-20
    • 2020-08-02
    • 1970-01-01
    • 2019-04-02
    • 1970-01-01
    • 1970-01-01
    • 2021-05-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多