2017-08-01 117 views
0

我遇到了問題https://od-api.oxforddictionaries.com:443/api/v1/entries/en/ace/pronunciations API我在其他API上使用了此代碼。 我試圖使用POSTMAN及其工作。所以我認爲問題出在我的代碼上。對預檢請求的角度響應未通過訪問控制檢查

getWord(word) { 
    let headers = new Headers(); 
    headers.append('Accept','application/json'); 
    headers.append('app_id','xxxxxx'); 
    headers.append('app_key','xxxxx'); 

    return this._http.get('https://od-api.oxforddictionaries.com:443/api/v1/entries/en/ace/pronunciations',{headers:headers}) 
    .map(res => res.json()); 
} 

錯誤:

enter image description here

回答

1

通知,指出該錯誤消息的一部分:

這表明認證失敗。

因此,這可能意味着您沒有在必要的app_idapp_key請求標頭中給出有效值。檢查這些值並(重新)註冊或根據需要生成新的API密鑰。

否則,https://od-api.oxforddictionaries.com API端點響應確實包含Access-Control-Allow-Origin響應頭,包括OPTIONS響應:

$ curl -X OPTIONS -i \ 
    --header "Origin: http://example.com" \ 
    --header "Access-Control-Request-Headers: app_id, app_key" \ 
    --header "Access-Control-Request-Method: GET" \ 
    --header "app_id: 023xxxxx" \ 
    --header "app_key: e6a772cxxxxxxxxxxxxxxxxxxxxxxxxx" \ 
    "https://od-api.oxforddictionaries.com/api/v1/entries/en/ace/pronunciations" 

HTTP/1.1 200 OK 
Access-Control-Allow-Headers: app_id 
Access-Control-Allow-Methods: DELETE, GET, HEAD, OPTIONS, PATCH, POST, PUT 
Access-Control-Allow-Origin: http://example.com 
Allow: HEAD, OPTIONS, GET 
Content-Type: text/html; charset=utf-8 
Date: Tue, 01 Aug 2017 22:49:53 GMT 
Server: openresty/1.9.7.4 
version: v1.1.0-601-g45837e9 
Content-Length: 0 
Connection: keep-alive 

所以,如果你解決你的代碼發送有效app_idapp_key請求頭的值,它應該工作。

相關問題