Ionic-Cli代理设置:

打开ionic.config.json文件,添加proxies代理配置字段:

{
  "name": "ion",
  "app_id": "",
  "v2": true,
  "typescript": true,
  "proxies": [
    {
      "path": "/web",
      "proxyUrl": "http://127.0.0.1/phpResty/web"
    }
  ]
}

  

之后在provider中这样调用即可:

  url:string = "/web/";
  api(){
    return new Promise((resolve, reject)=>{
      this.http.get(this.url + "api.php").subscribe(res => {
        resolve(res.json)
      }, err => {
        reject(err);
      });
    });
  }

  

此时访问 http://localhost:8100/web/api.php 等同于访问 http://127.0.0.1/phpResty/web/api.php

从而避开了因端口不同而产生的跨域问题。

 

 

参考:http://www.jianshu.com/p/e9c85dbf406d

http://blog.csdn.net/haozhoupan/article/details/51149896

相关文章:

  • 2021-09-16
  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2022-12-23
  • 2021-10-17
  • 2021-09-06
  • 2022-01-21
猜你喜欢
  • 2021-12-30
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-03
  • 2022-12-23
相关资源
相似解决方案