是否可以在Ionic2/Angular2应用程序中使用HTTPS/SSL?

pet*_*erc 0 javascript cordova ionic2 angular

我一直在寻找一个关于如何在Ionic2/Angular2 Cordova移动应用程序中使用SSL/https的示例,但一直未能找到.

有推荐的方法吗?我一直在寻找,{ Http } from '@angular/http'但看不到任何明显的暴露.

任何指针都将非常感激.

Dan*_*mon 5

使用Angular2时,当你看到Http对象时,它可能会有点误导,它会让你认为应该有一个Https对象,而没有.要将https与Http对象一起使用,只需在URL字符串参数中指定任何方法[get(URL),post(URL,body)...].例如

export class Example{
  private _dataFromGet: {};
  constructor(private _http:Http){
    this._dataFromGet = {};
  }

  retrieveData():void{
    _http.get("https://SomeUrlHere")
         .map(res:Response => res.json())
         .subscribe(data => {
           this._dataFromGet = data;
         });
  }
}
Run Code Online (Sandbox Code Playgroud)