public autocomplete(w):any {
let options = {
headers:{
'Accept': 'application/json',
'app_id': 'myid',
"app_key": "mykey"
} as any
}
this.word = w.toLowerCase() ;
let myResponse = this._http.get('https://od-api.oxforddictionaries.com:443/api/v1/search/en/translations=es?q='+this.word,options);
return myResponse;
}
我已经尝试了所有类型的报头,请求设置用于身份验证的牛津API报头,但只有得到的结果是: 403禁止!
请给我推荐正确的方法
发布于 2018-07-06 13:12:26
我对你的代码做了一点重构,并创建了一个头对象和请求选项。应该能行得通。从angular导入以下http模块
import { Http, Response, RequestOptions, Headers } from '@angular/http';
.你的方法应该如下所示。如果它对你有效,请及时通知我。
public autocomplete(w): any {
const baseUrl =
'https://od-api.oxforddictionaries.com:443/api/v1/search/en/translations=es?q=';
w = w.toLowerCase();
const headers = new Headers();
headers.append('Content-Type','application/json');
headers.append('app_id','myId');
headers.append('app_key','myKey');
const options = new RequestOptions({ headers: headers });
return this.http.get(baseUrl + w, options);
}
https://stackoverflow.com/questions/51203029
复制相似问题