1

I try to make an http request to a freebox ( I don't know if it's exist outside france )

The freebox don't access the CORS request, but she make what I will.

For example if I make a request for power :

http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1

The freebox player start, and I have a CORS error:

XMLHttpRequest cannot load http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.

It's okay, but I will check the http header for this request, for example if I will check if my code is good, the freebox return 403 for bad code.

I tried to get the statusCode with Jquery :

            xhr = $.ajax({
            method: "GET",
            url: url,
            crossDomain: true,
            statusCode: {
                500: function () {
                    alert("Une erreur s'est produite !");
                },
                403: function(){
                    alert("aaaaa")
                    throw new badTelecommandeCode();
                },
                404: function(){
                    throw new freeboxNotFound();
                },
                0: function(){console.log(0)}
            },
            error: function (err) {
                console.log(err);
            }
        });

All this time, the status code is 0, and "error" don't launch. I have this error in console :

XMLHttpRequest cannot load http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 403.

You can see the end of this answer

"The response had HTTP status code 403.". Just before jquery write an error ( in red ):

GET http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1 

I try to catch the error :

        try{
        xhr = $.ajax({
            method: "GET",
            url: url,
            crossDomain: true,
            statusCode: {
                500: function () {
                    alert("Une erreur s'est produite !");
                },
                403: function(){
                    alert("aaaaa")
                    throw new badTelecommandeCode();
                },
                404: function(){
                    throw new freeboxNotFound();
                }
            },
            error: function (err) {
                console.log(err);
            }
        });
    }
    catch(err){
        console.log(err);
    }

I have try to search, where the error has catch by jquery :

http://code.jquery.com/jquery-2.1.4.js line 8634

Do You find a way for catch the CORS message, and parse it, or catch the jquery message, and why not get the statusCode or any information .

For the little troller, the way "Send a request to freebox developer for accept CORS" is already make, but no answer. I can't pass by a webserver .

My Current challenge is : "I'm a lambda user will see my TV, but my Free Tv Remote don't work, what I can make easily, with my smartphone/PC"

UPDATE1 : I have make an example :

if it's work good :

    xhr = $.ajax({
    method: "GET",
    url: "http://hd1.freebox.fr/pub/remote_control?code=5818261&key=right&long=false&repeat=1",
    crossDomain: true,
    statusCode: {
        500: function () {
            alert("Une erreur s'est produite !");
        },
        403: function(){
            alert("badTelecommandeCode")
        },
        404: function(){
            alert("freeboxNotFound")
        }
    },
    error: function (err) {
        // console.log(err);
    },
    fail:function(jqxhr, textStatus, errorThrown) {
        // console.log(errorThrown);
    }
});

Good key, good code, my TV make the action, and return a CORS error CORS Without http error

I will catch, if the code is bad, or if the key doesn't exist :

        xhr = $.ajax({
    method: "GET",
    url: "http://hd1.freebox.fr/pub/remote_control?code=5818261&key=ping",
    crossDomain: true,
    statusCode: {
        500: function () {
            alert("Une erreur s'est produite !");
        },
        403: function(){
            alert("badTelecommandeCode")
        },
        404: function(){
            alert("freeboxNotFound")
        }
    },
    error: function (err) {
        // console.log(err);
    },
    fail:function(jqxhr, textStatus, errorThrown) {
        // console.log(errorThrown);
    }
});
xhr = $.ajax({
    method: "GET",
    url: "http://hd1.freebox.fr/pub/remote_control?code=222222&key=ping",
    crossDomain: true,
    statusCode: {
        500: function () {
            alert("Une erreur s'est produite !");
        },
        403: function(){
            alert("badTelecommandeCode")
        },
        404: function(){
            alert("freeboxNotFound")
        }
    },
    error: function (err) {
        // console.log(err);
    },
    fail:function(jqxhr, textStatus, errorThrown) {
        // console.log(errorThrown);
    }
});

CORS error with http status error I have a CORS, no problem, but how I can catch the text, say the http status .

For information : freebox.fr is a NAT rules, redirect to my router ( the freebox ), hdX.freebox.fr go to the API for TV player hd number X

thib3113
  • 564
  • 7
  • 19

1 Answers1

0

Still not certain interpret Question correctly. There does not appear to be a response returned from url . 0 does not appear to be a valid HTTP response code see HTTP status code 0 - what does this mean for fetch, or XMLHttpRequest? . The error logged to console

GET http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1 net::ERR_CONNECTION_TIMED_OUT 

after request below

var xhr = new XMLHttpRequest();
 xhr.open("GET", "http://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1", true);
 xhr.onload = function() {
   console.log(this.status)
 }
 xhr.onerror = function(e) {
   console.log(e, this.status)
 }
 xhr.send();
Community
  • 1
  • 1
guest271314
  • 1
  • 15
  • 104
  • 177
  • I Have the same return if it's work or not :/, the status is "0" – thib3113 May 09 '15 at 16:10
  • @thib3113 What is requirement ? , expected result ? – guest271314 May 09 '15 at 16:15
  • 1 - check if the remote tv network code is good ( code=XXX in http ), this return http error 403 if not valid but the server don't accept CORS – thib3113 May 09 '15 at 16:19
  • @thib3113 Tried opening new tab , typing _"http ://hd1.freebox.fr/pub/remote_control?code=5818260&key=power&long=false&repeat=1"_ into address bar, press enter, open `console` , see "network" tab ? There does not appear to be a response returned from `url` ? – guest271314 May 09 '15 at 16:23
  • yes, it's work for me ( but, it's not my problem ), i will make this programaticaly, so I have update my current challenge in topic . – thib3113 May 09 '15 at 16:28
  • Is requirement to `catch` `statusCode` `0` , then do stuff ? – guest271314 May 09 '15 at 16:34
  • no, i will catch the real status code, the same Status code i have in the console by the error ( see in topic ) – thib3113 May 09 '15 at 16:48
  • @thib3113 Not certain interpret requirement correctly ? – guest271314 May 09 '15 at 17:18
  • juste make a http call for get the http status of this, and make in function . – thib3113 May 09 '15 at 17:21
  • you have an ERR_CONNECTION_TIMED_OUT because you don't have a freebox . hd1.freebox.fr is a specific routage rule create by the freebox . the number after "hd" is the number of your hd player – thib3113 May 09 '15 at 18:54
  • @thib3113 Ok. Not certain how can help ? The `fail:` is not an options property of `$.ajax(options)` , but a separate method ; see http://api.jquery.com/deferred.fail/ – guest271314 May 09 '15 at 19:53
  • (i have see your comment before update), so, for the documentation, it's a big joke ... this API is never document ... she was make for a late version, and delete, and she come back, but without any informations ... a little informations in the web :/ I look with fail . I have try with parse an iframe, but she have a CORS too :/ **update :** I have try with .fail(), but it's return the same information, status : 0, and text : "error" – thib3113 May 09 '15 at 20:17
  • @thib3113 Actually attempted to visit "freebox.fr" ; "You attempted to reach **freebox.fr**, but instead you actually reached a server identifying itself as ***.free.fr**" – guest271314 May 09 '15 at 21:06
  • yes and ? If I go on http://mafreebox.free.fr or her IP : http://212.27.38.253/ , I see : http://www.zupmage.eu/i/aUCU0vTk3L.jpg – thib3113 May 09 '15 at 22:31