android - 尝试在 android 上运行 ionic 项目时连接到 mysql 数据库失败
问题描述
我正在尝试使用 nodejs 作为服务器运行离子应用程序以连接到 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
推荐阅读
- javascript - 在DataTable中选择一行的按钮
- python-3.x - 有没有办法将位转换为int?
- cobol - AcuCobol 外部调用
- android - mpandroidchart折线图x轴标签重叠问题发生
- protocol-buffers - grpc:如何返回对另一个服务的引用
- database - 如何从给定表中检索后半部分记录
- node.js - 尝试将新变量推送到数组时“userIDs.push 不是函数”
- node.js - NodeJs error: Cannot GET /admin when using router
- django - 导出pdf文件
- vba - 在幻灯片上重新定位形状和文本框