微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

为什么只有在运行react-native-debugger时此请求才起作用?

如何解决为什么只有在运行react-native-debugger时此请求才起作用?

我有一个非常奇怪的问题:我正在React Native应用程序中向本地计算机发送axios请求。

这是请求的代码

const client = axios.create({
    baseURL: 'https://192.168.178.20:5000/',headers: {
        'Content-Type': 'application/x-www-form-urlencoded'
    }
});
const params = new URLSearchParams();
params.append('scope','openid profile offline_access email');
params.append('username','<username>');
params.append('password','<password>');
const response = await client.post<AuthResponse>('connect/token',params);

但是,如果我在博览会应用程序中激活了远程调试并打开了https://192.168.178.20:5000/,则请求仅到达我的后端(正在react-native-debugger上运行)。否则,我会收到此AxiosError:

{"message":"Network Error","name":"Error","stack":"createError@http://192.168.178.20:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:142265:26\nhandleError@http://192.168.178.20:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:142169:27\ndispatchEvent@http://192.168.178.20:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:32672:31\nsetReadyState@http://192.168.178.20:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:31756:33\n__didCompleteResponse@http://192.168.178.20:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:31572:29\nemit@http://192.168.178.20:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:3921:42\n__callFunction@http://192.168.178.20:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:3149:36\nhttp://192.168.178.20:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:2881:31\n__guard@http://192.168.178.20:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:3103:15\ncallFunctionReturnFlushedQueue@http://192.168.178.20:19001/node_modules%5Cexpo%5CAppEntry.bundle?platform=android&dev=true&minify=false&hot=false:2880:21\ncallFunctionReturnFlushedQueue@[native 
code]","config":{"url":"connect/token","method":"post","data":"scope=openid profile offline_access whee_api email&username=bob&password=BobDerBaumeister5%2B&client_id=whee_mobile&grant_type=password","headers":{"Accept":"application/json,text/plain,*/*","Content-Type":"application/x-www-form-urlencoded"},"baseURL":"https://192.168.178.20:5000/","transformRequest":[null],"transformResponse":[null],"timeout":0,"xsrfCookieName":"XSRF-TOKEN","xsrfheaderName":"X-XSRF-TOKEN","maxContentLength":-1,"maxBodyLength":-1}}

我真的不知道react-native-debugger与这个axios请求有什么关系。

我正在使用以下版本:

  • 反应本机: 0.63.23
  • 博览会: 39.0.3
  • Axios: 0.20.0
  • 反应本机调试器: 0.11.5

需要更多详细信息吗?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。