我在他们的文档中看到支持 CORS。但是我尝试从 JavaScript 发出请求没有成功。
请求此 URL:
我收到标准错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://google.com' is therefore not allowed access.
UPD: bitly 文档 - http://dev.bitly.com/cors.html
最佳答案
如果还有人遇到这个问题。发生这种情况的原因是来自 bitly 的选项(预检)响应不包含“Access-Control-Allow-Origin” header 。
为了解决这个问题,我使用了不发送预检的 XMLHttpRequest。
let xhr = new XMLHttpRequest();
let url = 'https://api-ssl.bitly.com/v3/shorten?longUrl=https://google.com/&access_token=token'
xhr.open('GET', url);
xhr.onreadystatechange = function() {
if(xhr.readyState === 4) {
if(xhr.status===200) {
console.log(xhr.responseText)
} else {
console.log(xhr)
}
}
};
xhr.send();
其实在bitlly的documentation里面有提到
关于javascript - bitly API支持CORS吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26141578/