Note that there are some explanatory texts on larger screens.

plurals
  1. POCors XmlHttpRequest and Response
    primarykey
    data
    text
    <h2>Description of Task</h2> <p>I'm creating a program with a client/server architecture. The server is a javascript script running in the users's browser, the client is a application running on the user's local machine. The script posts a GET request to a port on 127.0.0.1; 2000 for example. The client reads the message, does some action, and posts a reply back to the server.</p> <h2>Description of Problem</h2> <p>This type of interaction is considered to be cross-origin resource sharing. I've read the material <a href="https://developer.mozilla.org/en/http_access_control" rel="nofollow">here</a> and written my program to respond to the request using with appropriate cors header messages. Unfortunately I seem to be getting the error message:</p> <p><code>XMLHttpRequest cannot load http://127.0.0.1:2000/?Command=test&amp;Parameters=1234. Origin http://127.0.0.1 is not allowed by Access-Control-Allow-Origin.</code></p> <h2>Full Http Exchange</h2> <pre><code>GET /?Command=test&amp;Parameters=1234 HTTP/1.1 Host: 127.0.0.1:2000 Connection: keep-alive Origin: http://127.0.0.1 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.11 (KHTML, like Geco) Chrome/17.0.963.79 Safari/535.11 Accept: */* Referer: http://127.0.0.1/test/main.php Accept-Encoding: gzip,deflate,sdch Accept-Language: en-US,en;q=0.8 Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3 HTTP/1.1 200 OK Server: Custom-Gnat-Client-v1.0 Access-Control-Allow-Origin: * Origin: http://127.0.0.1 Content-Length: 12 Keep-Alive: timeout=2, max=100 Connection: Keep-Alive Content-Type: text/plain Success </code></pre> <h2>Relevant Code</h2> <p>In main.js:</p> <pre><code>var Is_IE = window.XDomainRequest ? true : false; var Cross_Domain_xmlhttp = Create_Cross_Domain_Request(); function Create_Cross_Domain_Request(){ var request; if(Is_IE) request = new window.XDomainRequest(); else{ if(window.XMLHttpRequest){ request=new XMLHttpRequest(); } else { request=new ActiveXObject("Microsoft.XMLHTTP"); } } return request; } ... var URL = "http://127.0.0.1:2000/"+"?Command="+Command_String+"&amp;Parameters=" +Parameters; if (Cross_Domain_xmlhttp){ if(Is_IE){ Cross_Domain_xmlhttp.onload=function(){ console.log(Cross_Domain_xmlhttp.responseText); } Cross_Domain_xmlhttp.open("GET", URL, true); Cross_Domain_xmlhttp.send(); } else { Cross_Domain_xmlhttp.open('GET', URL, true); Cross_Domain_xmlhttp.onreadystatechange=function(){ if (Cross_Domain_xmlhttp.readyState==4 &amp;&amp; Cross_Domain_xmlhttp.status==200){ console.log(Cross_Domain_xmlhttp.responseText); } } Cross_Domain_xmlhttp.send(); } } else { alert("The browser does not support XDomainRequest or XmlHttpRequest"); } </code></pre> <p>The client code isn't relevant currently but I will post if requested.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload