发布于 2018-02-27 10:29:26
您将使用http API直接从您的角度应用程序中消费那里的API。
请查看来自这里的教程,以便以角度处理https请求。
请查看下面的片段以寻求帮助,
import { Headers, RequestOptions } from '@angular/http';
//your component method
doSearch() {
let subscriptionKey = 'YOUR-SUBSCRIPTION-KEY';
let customConfigId = 'YOUR-CUSTOM-CONFIG-ID';
let searchTerm = 'microsoft';
let headers = new Headers();
headers.append('Ocp-Apim-Subscription-Key', subscriptionKey);
let opts = new RequestOptions();
opts.headers = headers;
// here your url
let url = 'https://api.cognitive.microsoft.com/bingcustomsearch/v7.0/search?' +
'q=' + searchTerm +
'&customconfig=' + customConfigId,
// http rquest
this.http.get(url, opts).subscribe(
res => console.log('handle your response',res.json()),
msg => console.error(`Error: ${msg.status} ${msg.statusText}`)
);
}不记得了,但你可以试着玩上面的片段。
否则,如果后端有一个node,那么为Bing Custom Search endpoint创建自己的endpoints,并使用请求处理程序在应用程序中使用它们。
希望这能帮到你!!
https://stackoverflow.com/questions/49006045
复制相似问题