JavaScript: Cross-Origin Read Blocking (CORB) 在通过 gitlab 请求时阻止跨源响应 api
JavaScript: Cross-Origin Read Blocking (CORB) blocked cross-origin response when request through gitlab api
我已经通过gitlab成功收到了用户的id api,但是当我试图收到用户的项目列表时,chrome returns CORB。
我已经使用 GitLab api v4 成功收到了 ID 和所有其他用户信息。但是当我试图接收用户的回购列表时,我收到了 CORB 块,但在响应文本中什么也没有得到。直接输入网址可以看到json形式的数据。如果我直接使用jQuery.getJSON,它会要求我在header中添加X-Requested-With或Origin,我不知道如何实现。
var target = 'https://gitlab.com/api/v4/users/'+doc.data().gitlab_id+'/projects?callback=?';
console.log(target);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = process;
xhr.open("GET", target, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('responseType', 'text/plain');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.send();
function process() {
console.log(xhr);
我希望获得 json 数据,但现在响应文本为空,并且 returns 下面是一条消息:
跨源读取阻止 (CORB) 阻止了跨源响应https://gitlab.com/api/v4/users/USER_ID/projects?callback=jQuery11130057655514217979986_1563975117007&_=1563975117008 with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 了解更多详细信息。
对于面临相同问题的任何人:
尝试在您的请求之前添加“https://cors-anywhere.herokuapp.com/”url。
例如,您可以使用
'https://cors-anywhere.herokuapp.com/https://api.linkedin.com/v2/me?oauth2_access_token=' + access_token;
从 linkedin 获取信息而不受 cors 政策的困扰。
我已经通过gitlab成功收到了用户的id api,但是当我试图收到用户的项目列表时,chrome returns CORB。
我已经使用 GitLab api v4 成功收到了 ID 和所有其他用户信息。但是当我试图接收用户的回购列表时,我收到了 CORB 块,但在响应文本中什么也没有得到。直接输入网址可以看到json形式的数据。如果我直接使用jQuery.getJSON,它会要求我在header中添加X-Requested-With或Origin,我不知道如何实现。
var target = 'https://gitlab.com/api/v4/users/'+doc.data().gitlab_id+'/projects?callback=?';
console.log(target);
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = process;
xhr.open("GET", target, true);
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xhr.setRequestHeader('responseType', 'text/plain');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.send();
function process() {
console.log(xhr);
我希望获得 json 数据,但现在响应文本为空,并且 returns 下面是一条消息:
跨源读取阻止 (CORB) 阻止了跨源响应https://gitlab.com/api/v4/users/USER_ID/projects?callback=jQuery11130057655514217979986_1563975117007&_=1563975117008 with MIME type application/json. See https://www.chromestatus.com/feature/5629709824032768 了解更多详细信息。
对于面临相同问题的任何人:
尝试在您的请求之前添加“https://cors-anywhere.herokuapp.com/”url。
例如,您可以使用 'https://cors-anywhere.herokuapp.com/https://api.linkedin.com/v2/me?oauth2_access_token=' + access_token; 从 linkedin 获取信息而不受 cors 政策的困扰。