mardi 2 mai 2017

Get JSON API form docker host

I build qBittorrent from Dockertools box. And qBittorrent have a API get torrentlist . It's like that :

GET /query/torrents HTTP/1.1
User-Agent: Fiddler
Host: 127.0.0.1
Cookie: SID=your_sid

But i run it in this host : http://ift.tt/1N1yiIz so i use loadJSON() of javascript to catch what i want . But it's always fail . This in console :

XMLHttpRequest cannot load http://ift.tt/2p0Wgin. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

my code here :

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://ift.tt/2p0Wgin", function(response) {

    var actual_JSON = JSON.parse(response);
    console.log(actual_JSON);
  }, 'jsonp');
}

i read some question but it doesn't work. So any one can help me . Thank a lot !




Aucun commentaire:

Enregistrer un commentaire