简体   繁体   English

尝试在 android 上运行 ionic 项目时连接到 mysql 数据库失败

[英]Connection to mysql database failed while trying to run ionic project on android

I am trying to run an ionic application using nodejs as server to connect to mysql database on android , the application runs perfectly on lab but when it comes to android it failed to connect to localhost , apparently the emulator couldn't recognize the address am using .This is the code am using in my ionic service :我正在尝试使用 nodejs 作为服务器运行 ionic 应用程序以连接到 android 上的 mysql 数据库,该应用程序在实验室上完美运行,但是当涉及到 android 时,它无法连接到 localhost,显然模拟器无法识别正在使用的地址.这是我在离子服务中使用的代码:


export class CandidatService {
  base_path = 'http://10.0.2.2:1617';

  constructor(private http: HttpClient) { }

  // Http Options
  httpOptions = {
    headers: new HttpHeaders({
      'Content-Type': 'application/json'
    })
  }

  getAllCandidats(): Observable<Candidat[]>
  {
    return this.http
      .get<Candidat[]>(this.base_path+"/selectAllCandidats", this.httpOptions)
      .pipe()
  }
}```

is this ip and port is the valid nodejs server app?这个 ip 和端口是有效的 nodejs 服务器应用程序吗?

http://10.0.2.2:1617

do you have console.log on what happen on the nodejs ?你有关于 nodejs 发生了什么的 console.log 吗? is your nodejs server and your android is running on same wifi ?您的 nodejs 服务器和您的 android 是否在same wifi上运行?

if no, then you might need to use public ip or the simple one is using ngrok如果不是,那么您可能需要使用公共 ip 或者简单的使用ngrok

reference : https://ngrok.com/参考: https : //ngrok.com/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM