在角度获取404错误的牛津字典API

时间:2018-12-29 21:11:58

标签: angular typescript api web-applications

添加proxy.conf.json后,我的代码在使用angular访问oxford dicitonary api时仍然显示404错误

service.ts

 getData(word: string) {
     console.log('entered');
    const firstHeaders = new HttpHeaders();
    const headers: HttpHeaders = firstHeaders
      .append('Accept', 'application/json')
      .append('app_id', 'aaaaaa')
      .append('app_key', 'adfhsdkfdkjfkdsj51');
      console.log('reached');
    return this.http.get(`/api/search/en?q=${word}&prefix=false`, { 
headers });
  }

proxy.conf.json

{
  "/api": {
    "target": " https://od-api.oxforddictionaries.com",
    "secure": true,
    "changeOrigin": true,
    "logLevel": "debug",
    "headers": {
      "Accept": "application/json",
      "app_id": "*****",
      "app_key": "****"
    },
    "pathRewrite": { "^/api": "" }
  }
}

0 个答案:

没有答案