React native 反应本机+;Axios:仅在android设备上出现网络错误
我正在开发一个与Axios Api连接的React本机应用程序。当我在模拟器上时,我的电话工作正常,但当我使用安卓手机时,我会收到“网络错误” 我已经在寻找解决方案,但没有找到我的案例。我已经尝试将android:usesCleartextTraffic=“true”放入清单中,但这不起作用 我的服务器是本地服务器 以下是我连接到API的代码:React native 反应本机+;Axios:仅在android设备上出现网络错误,react-native,axios,React Native,Axios,我正在开发一个与Axios Api连接的React本机应用程序。当我在模拟器上时,我的电话工作正常,但当我使用安卓手机时,我会收到“网络错误” 我已经在寻找解决方案,但没有找到我的案例。我已经尝试将android:usesCleartextTraffic=“true”放入清单中,但这不起作用 我的服务器是本地服务器 以下是我连接到API的代码: import Axios from 'axios'; const devURL = 'http://my_ip:8080'; const apiConf
import Axios from 'axios';
const devURL = 'http://my_ip:8080';
const apiConfigure = '/api/';
const baseURL = devURL + apiConfigure;
console.log('baseUrl', baseURL);
export interface IResponse {
success: boolean;
error?: string;
}
export const rtv = Axios.create({
baseURL,
headers: { 'Content-Type': 'application/json', 'Accept': 'application/json' },
});
下面是一个api调用示例:
export const fetchToken = async (email: string, password: string): Promise<IToken> => {
try {
const {data} = await rtv.post('auth/signin', {email:email, password});
console.log('data', data);
return data;
} catch (e) {
console.log(e);
toastError('Error in connection');
return null;
}
};
export const fetchToken=async(电子邮件:string,密码:string):Promise=>{
试一试{
const{data}=wait rtv.post('auth/signin',{email:email,password});
console.log('data',data);
返回数据;
}捕获(e){
控制台日志(e);
toastError(“连接错误”);
返回null;
}
};
谢谢您的帮助。我假设您的设备与您的计算机位于同一个wifi网络上?是的,在同一个网络上检查您的代理我假设您的设备与您的计算机位于同一个wifi网络上?是的,在同一个网络上检查您的代理