[英]Connection to mysql database failed while trying to run ionic project on android
我正在尝试使用 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()
}
}```
这个 ip 和端口是有效的 nodejs 服务器应用程序吗?
http://10.0.2.2:1617
你有关于 nodejs 发生了什么的 console.log 吗? 您的 nodejs 服务器和您的 android 是否在same wifi
上运行?
如果不是,那么您可能需要使用公共 ip 或者简单的使用ngrok
参考: https : //ngrok.com/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.