为什么只有在运行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 (将#修改为@)