2

我正在尝试在我的 iOS 设备中使用“Ionic DevApp”模拟我的 Ionic 应用程序,但是我无法从设备连接到在我的计算机中运行的 localhost api。我已将 API 请求端点更改为我计算机的本地 IP 地址,但没有任何变化。这是我正在使用的 URL 示例:

http://192.168.0.145:8080/countries

这是完整的提供者:

import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';   

@Injectable()
export class CountryProvider {

private url: string; 

constructor(public http: HttpClient) {
  this.url = "http://192.168.0.145:8080/countries";
}

getCountries() {
  return this.http.get(this.url);
} 

当然,如果我在计算机浏览器中运行该应用程序,它就可以正常工作。我在 iOS 设备浏览器上检查了相同的 URL,没问题。

4

0 回答 0