我从Dockertools框中构建qBittorrent。而qBittorrent有一个API 获得洪流列表。这就像:获取JSON API表单码头主机
GET /query/torrents HTTP/1.1
User-Agent: Fiddler
Host: 127.0.0.1
Cookie: SID=your_sid
但我在这台主机上运行它:http://192.168.99.100:8080/,所以我使用JavaScript的loadJSON()来捕捉我想要什么。但它总是失败。 这控制台:
XMLHttpRequest cannot load http://192.168.99.100:8080/query/torrents?filter=uploading&appid=f782f1c06749ea791dcb5d22219adf068a0d16a5a2c7b6686b17459562eb6b4f. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
我的代码在这里:
var torrent_peer;
function loadJSON(url, callback) {
var xobj = new XMLHttpRequest();
if (xobj) {
xobj.overrideMimeType("application/json");
xobj.open('GET', url, true); // Replace 'my_data' with the path to your file
xobj.withCredentials = true;
xobj.onreadystatechange = function() {
if (xobj.readyState == 4 && xobj.status == "200") {
callback(xobj.responseText);
}
};
xobj.send();
}
}
function load() {
loadJSON("http://192.168.99.100:8080/query/torrents?filter=uploading&appid=f782f1c06749ea791dcb5d22219adf068a0d16a5a2c7b6686b17459562eb6b4f", function(response) {
var actual_JSON = JSON.parse(response);
console.log(actual_JSON);
}, 'jsonp');
}
我读了一些问题,但它不工作。所以任何人都可以帮助我。非常感谢 !
如何运行此chrome --disable-web-security –