我想调用一个在用户系统中运行的第三方桌面应用程序,该应用程序的端口在3000处打开,当用户打开我的网站时,我向其本地主机发出请求:3000端口并获取数据,但第3方应用程序没有为CORS设置响应标头,因此我无法使用此策略进行同步,有人知道这样做的方法吗? 在这里,我使用ngrok进行隧道传输,但仍然无法执行。
xhr.open("POST", 'https://576b4cc1.ngrok.io', true);
//Send the proper header information along with the request
xhr.setRequestHeader("Content-Type", "text/plain");
xhr.onreadystatechange = function () { // Call a function when the state changes.
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
// Request finished. Do processing here.
console.log("In ready state exchange: " + xhr.responseText);
resolve();
}
}
xhr.onload = function (data) {
console.log("In onload : " + data);
}
xhr.onerror = function (err) {
console.log("In error: " + JSON.stringify(err, ["message", "arguments", "type", "name"]));
console.log('Data incase : ' + xhr.statusText);
}
xhr.send(reqObj.data);
答案 0 :(得分:-1)
您可以使用禁用网络安全性的标志从命令行启动浏览器,例如使用chrome,您可以执行以下操作:
chrome --disable-web-security
也有Chrome插件可以让您像https://chrome.google.com/webstore/detail/allow-cors-access-control/lhobafahddgcelffkeicbaginigeejlf
那样做