Get方法通过代理在localhost中起作用,但在设备或仿真上不起作用

时间:2018-12-05 16:14:22

标签: javascript android ionic-framework http-headers

由于CORS问题,get中的getNews function方法在本地主机上可以借助代理正常工作,但是,在使用.apk从设备进行测试或通过模拟网站进行测试时如果使用Android Studio或XCode,则map方法的响应为空。

问题可能是什么原因?

import { Headers , Response } from "@angular/http";
export class NewsService {
  getNews(url) {

    let url = 'https://admin:password@portal-domain.com:4444/news/_search';
    const headers = new Headers({'Content-Type': 'application/json', withCredentials: true});

    return this.http.get(url, {headers: headers})
      .map((response: Response) => {
        let body = response.json();
        if (body) {
          return body.data || body;
        } else {
          return {};
        }
      });
  }
}

export class NewsPage {
  newsArr;

  constructor(private newsService: NewsService);

  newsLoad() {
    this.newsArr = [];

    this.newsService.getNews(this.url)
      .subscribe(console.log);

}

文件:ionic.config.json

    {
      "name": "my_app",
      "integrations": {
        "cordova": {}
      },
      "type": "ionic-angular",
      "proxies": [
        {
          "path":"/_search",
          "proxyUrl": "https://admin:password@portal-domain.com:4444/news/_search"
        }
      ]
    }

https://admin:password@portal-domain.com:4444/news/_search”中的邮递员标题

content-type →application/json; charset=UTF-8
content-encoding →gzip
content-length →97562

0 个答案:

没有答案