[英]React Native cannot connect to localhost from another device
I use Django rest framework as my API, however, I'm unable to connect to localhost from my android device (not an emulator).我使用 Django rest 框架作为我的 API,但是,我无法从我的 android 设备(不是模拟器)连接到 localhost。 I have gone through many questions on StackOverflow and Github but none worked
我在 StackOverflow 和 Github 上遇到了很多问题,但都没有奏效
here is my code这是我的代码
import { create } from 'apisauce';
const apiClient = create({
baseURL: 'http://tried-many-things-but-none-worked:8000',
});
// getting data is straight forward
import client from './client';
const getChat = id => client.get("/chat/get_chat/${id}/";
I tried many solutions but none worked for me.我尝试了很多解决方案,但没有一个对我有用。 I tried using
我尝试使用
And nothing worked for my external device!对我的外部设备没有任何作用! I would really appreciate any helpÏ
我真的很感激任何帮助Ï
Please note that the problem isn't with the code as I tried to upload it to pythonanywhere web hosting service and used the URL I got from them and it was working fine with no errors (as well as from postman and the emulator)请注意,问题不在于代码,因为我试图将其上传到 pythonanywhere 网络托管服务并使用我从他们那里获得的 URL,并且它工作正常,没有错误(以及来自邮递员和模拟器)
Extra information: pc: macOS High Sierra version: 10.13.6, external device: Android额外信息:pc:macOS High Sierra 版本:10.13.6,外接设备:Android
You can use ngrok for this.您可以为此使用ngrok 。 You will get a new domain name from ngrok instead playing localhost/ip etc. You can check this documentation for more info https://ngrok.com/docs
您将从 ngrok 获得一个新域名,而不是播放 localhost/ip 等。您可以查看此文档以获取更多信息https://ngrok.com/docs
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.