Ionic HTTP请求插件/模块

时间:2017-08-03 21:14:39

标签: angular cordova http ionic-framework request

我对Ionic很新,我在Ionic中遇到一个简单的http请求问题。

首先,我尝试使用@angular/http进行oAuth2注册,但由于CORS原因而失败(使用access-control-allow-origin标头)。

我成功使用了原生离子@ionic-native/http - 模块。 后来我发现原生离子模块不支持PUT或DELETE请求(https://ionicframework.com/docs/native/http/)。

再次谷歌搜索我找到cordova-http-pluginhttps://github.com/wymsee/cordova-HTTP),但我不知道如何正确使用它。

我现在的问题是: 在Ionic / Angular中发出http请求的最佳方法是什么?

感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

有这个......

import { Http } from "@angular/http"

在你的构造函数中......

public http: Http

然后提出请求......

this.http.get('http://www.yourdomain.com/file.php).map(res => res.json()).subscribe(data => {
    console.log(data);
});

希望这有帮助。