【发布时间】:2020-06-20 22:48:13
【问题描述】:
我正在尝试使用 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()
}
}```
【问题讨论】:
-
你能分享错误日志吗?
-
您的移动应用程序和您的 nodejs 服务器应该在同一个 wifi 中运行,您可以连接到这个 IP 地址,或者正如答案中提到的那样,您可以使用 ngrok 服务获取 https URL,或者您需要将 nodejs 服务器部署在 AWS、heroku 等云提供商中的第三个选项
标签: android mysql node.js cordova ionic-framework