gpt4 book ai didi

javascript - Angular 4 - 请求的资源上不存在 'Access-Control-Allow-Origin' header

转载 作者:行者123 更新时间:2023-11-29 19:03:07 25 4
gpt4 key购买 nike

我试图在我的 Angular 4 应用程序中使用 Spotify/Musixmatch API 获取一些数据,但它不起作用。我不断收到此错误:

XMLHttpRequest cannot load http://api.musixmatch.com/ws/1.1/album.get?album_id=14250417&apikey=xyz010xyz. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:9000' is therefore not allowed access.

JS

  let headers = new Headers();
headers.append('Content-Type','application/json');
headers.append('Accept', 'application/json');
headers.append('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, DELETE, PUT');
headers.append('Access-Control-Allow-Origin', '*');
headers.append('Access-Control-Allow-Headers', "X-Requested-With, Content-Type, Origin, Authorization, Accept, Client-Security-Token, Accept-Encoding");
let options = new RequestOptions({ headers: headers });
console.log(options)
return this.http.get(this.url + 'album.get?album_id=' + album_id + '&apikey=' + this.apikey, options)
.map(res => res.json())
}

enter image description here

最佳答案

这是浏览器的问题,通常是安全问题,不允许其他可能容易导致 XSS 攻击的请求。如果只是为了开发,我建议你安装一个插件,它将在你的浏览器中禁用 plugin

如果用于生产,则需要配置 API。

关于javascript - Angular 4 - 请求的资源上不存在 'Access-Control-Allow-Origin' header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45347860/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com