Page 1 of 1

[CDS API] XmlHttpRequest from a not allowed IP

PostPosted: Tue Aug 06, 2013 2:54 pm
by kissskoool
Hi,

After my two first posts, i still have some questions, but i'm sure it will be useful for others too ;)

I'm trying to make a JS XmlHttpRequest like this :

  Code:
function cds_info(token, object_id){
   var xhr = new XMLHttpRequest();
   xhr.open("GET", "http://my_server_ip:23424/cds/browse/flv_player/"+object_id+"/BrowseMetadata/all/0/1?authToken="+token);
   xhr.setRequestHeader("Accept", "application/xml | application/json");
   xhr.onreadystatechange = function () {
     if (this.readyState == 4) {
      alert('Object_id: '+object_id+'\nStatus: '+this.status+'\nHeaders: '+JSON.stringify(this.getAllResponseHeaders())+'\nBody: '+this.responseText);
     }
   };
   xhr.send(null);
}


And i get this error message :

Origin http://my_server_ip is not allowed by Access-Control-Allow-Origin

How can i allow this request ?

Many thanks for your help !

Re: [CDS API] XmlHttpRequest from a not allowed IP

PostPosted: Tue Aug 06, 2013 5:32 pm
by zip
The accept-type is either application/xml or application/json. The API shows that in not so clean way, sorry about that.

It'll define if you get back XML or JSON, the choice is yours.

Re: [CDS API] XmlHttpRequest from a not allowed IP

PostPosted: Tue Aug 06, 2013 6:04 pm
by kissskoool
Thanks for your answer.
It was not exactly what i asked but it doesn't matter i found a solution for the Access-Control-Allow-Origin problem due to cross domain ajax limits.

i just did a reverse proxy to redirect http://my_server:23424/cds/... to http://my_server/cds/... so i remain on the same domain.

Re: [CDS API] XmlHttpRequest from a not allowed IP

PostPosted: Sun Aug 11, 2013 2:21 pm
by ailete
Hi kissskoool !

I encountered the same issue, but I did'nt manage to resolve it yet.
You say you found a solution by setting a reverse proxy... Can you explain how you did it please ? It would be really helpful for me.

Thanks a lot :D

Re: [CDS API] XmlHttpRequest from a not allowed IP

PostPosted: Mon Aug 12, 2013 12:25 pm
by kissskoool
Access-Control-Allow-Origin problems is due to a cross ajax request from a domain to another one.
The origin url and the destination url must have the same domain and port.

So http://my_server:23424/cds/ and http://my_server/cds/ are considered two different domains.

My solution is to redirect on my server http://my_server:23424/cds/ to http://my_server/cds/

To do that you have to activate mods proxy and proxy_http

then in your site apache virtualhost you'll have to add those lines :

  Code:
   
<Location /cds>
        ProxyPass http://127.0.0.1:23424/cds
        ProxyPassReverse http://127.0.0.1:23424/cds
    </Location>