本文整理匯總了TypeScript中@ionic-native/http.HTTP.get方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript HTTP.get方法的具體用法?TypeScript HTTP.get怎麽用?TypeScript HTTP.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類@ionic-native/http.HTTP
的用法示例。
在下文中一共展示了HTTP.get方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: Promise
return new Promise((resolve, reject) => {
if ("cordova" in window) {
this.nativeHttp.get(url, {}, {}).then(success => {
if (success.status == 200) {
resolve(JSON.parse(success.data));
}else {
reject(success.status);
}
}).catch(err => {
reject(err);
});
}else {
this.http.get(url)
.timeout(2000)
.map(res => res.json())
.subscribe(data => {
resolve(data);
}, err => {
if (err instanceof TimeoutError) {
err = 408;
}
reject(err);
});
}
});
示例2: getTTSAccessToken
// 百度TTS 合成token
getTTSAccessToken()
{
let url = "https://openapi.baidu.com/oauth/2.0/token";
let params = {
"grant_type": "client_credentials",
"client_id": "TPnGgO8zxIayL9iTTctlxqny",
"client_secret": "820591dad6912546574487991d6bcb7d"
};
if(this.platform.is("cordova"))
{
return Observable.fromPromise(this.nativeHttp.get(url, params, {})).map((res:any) =>{
return JSON.parse(res.data);
}).catch(this.handleError);
}
else
{
url = url.replace("https:/", "");
let searchParams = new URLSearchParams();
for(let key in params)
{
searchParams.set(key, params[key]);
}
let reqOpts = new RequestOptions({"search": searchParams, "headers": new Headers()});
return this.http.get(url, reqOpts).map(res=>{
return res.json();
}).catch(this.handleError);
}
}
示例3:
this.platform.ready().then(() => this.http.get(API_BASE, {}, {}))