【发布时间】:2016-07-31 14:27:38
【问题描述】:
我一直在寻找有关如何在 Ionic2/Angular2 Cordova 移动应用程序中使用 SSL/https 的示例,但一直没有找到。
有推荐的方法吗?我一直在查看{ Http } from '@angular/http',但看不到任何明显的暴露。
任何指针将不胜感激。
【问题讨论】:
标签: javascript cordova angular ionic2
我一直在寻找有关如何在 Ionic2/Angular2 Cordova 移动应用程序中使用 SSL/https 的示例,但一直没有找到。
有推荐的方法吗?我一直在查看{ Http } from '@angular/http',但看不到任何明显的暴露。
任何指针将不胜感激。
【问题讨论】:
标签: javascript cordova angular ionic2
使用 Angular2 时,当您看到 Http 对象时可能会产生一些误导,它会让您认为应该有一个 Https 对象,但实际上并没有。要将 https 与 Http 对象一起使用,您只需在任何方法 [get(URL), post(URL,body)...] 的 URL 字符串参数中指定它。例如
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;
});
}
}
【讨论】: