Note that there are some explanatory texts on larger screens.

plurals
  1. POjquery / soap request to local libcsoap/nanohttpd server -> Origin * is not allowed by Access-Control-Allow-Origin
    primarykey
    data
    text
    <p>I wrote a c-program which needs an interface for other programs, also for a webste. So i just choosed libcsoap to create a soap interface. The libcsoap-library is based on nanohttpd, a small http server written in c.</p> <p>I just implemented a few test functions, e.g. a <code>ping</code>-function which just returns an xml without any interesting data.</p> <p>I can call these functions with the help of libcsoap without any problems. But now, i try to call the soap interface from a dummy website. I just created a html file with a textarea and a button to send the textarea's content as raw xml.</p> <p>Then i try to put the answer into a <code>div</code> next to the <code>send</code>-button. This html-file is on my local machine <code>xubuntu-02</code> on an apache2 webserver.</p> <p>Here is the code:</p> <pre><code>&lt;HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"&gt; &lt;HEAD&gt; &lt;TITLE&gt;Debug Post&lt;/TITLE&gt; &lt;script src="http://code.jquery.com/jquery-1.9.1.min.js"&gt;&lt;/script&gt; &lt;script type="text/javascript"&gt; function submit_data() { var src = document.getElementById('data'); $.support.cors = true; $.ajax({ url: 'http://xubuntu-02:10000/tbs_blabla', type: 'POST', async: false, timeout: 30000, data: src.value, success: function(data) { alert('OK!'); /*document.getElementById('data').value = data;*/ }, fail: function() { alert('failed'); } }); } &lt;/script&gt; &lt;/HEAD&gt; &lt;BODY&gt; &lt;H1&gt;Debug Post&lt;/H1&gt; &lt;textarea id="data" rows="10" cols="80"&gt; &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt; &lt;SOAP-ENV:Header/&gt; &lt;SOAP-ENV:Body&gt; &lt;m:ping xmlns:m="urn:tbs_blabla"&gt; &lt;m:name xsi:type="xsd:string"&gt;Jonny B. Good&lt;/m:name&gt;&lt;/m:ping&gt; &lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt; &lt;/textarea&gt; &lt;p&gt; &lt;input type="button" value="Submit" onclick="submit_data();return false;" /&gt; &lt;/p&gt; &lt;p&gt; &lt;div id="res"&gt; &lt;/div&gt; &lt;/p&gt; &lt;/BODY&gt; &lt;/HTML&gt; </code></pre> <p>I use chromium to debug the code. There is can observe all http requests, there i always get the http status 200 for the answer. So... the request should be complete? If i check the log on the server side (libcsoap-log) i also can see that the xml was processed, a new xml was created and the new xml was sent.</p> <p>I also checked the request with wireshark, there it seems to be ok:</p> <pre><code>POST /tbs_blabla HTTP/1.1 Host: xubuntu-02:10000 Connection: keep-alive Content-Length: 425 Accept: */* Origin: http://xubuntu-02 User-Agent: Mozilla/5.0 (X11; Linux i686) AppleWebKit/537.17 (KHTML, like Gecko) Chrome/24.0.1312.56 Safari/537.17 Content-Type: application/x-www-form-urlencoded; charset=UTF-8 Referer: http://xubuntu-02/test.html 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 DNT: 1 &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt; &lt;SOAP-ENV:Header/&gt; &lt;SOAP-ENV:Body&gt; &lt;m:ping xmlns:m="urn:tbs_blabla"&gt; &lt;m:name xsi:type="xsd:string"&gt;Jonny B. Good&lt;/m:name&gt;&lt;/m:ping&gt; &lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt; HTTP/1.1 200 OK Date: Sun, 10 Mar 2013 13:28:33 GMT Server: Nano HTTPD library Content-Type: text/xml Content-Length: 417 &lt;SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" SOAP-ENV:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"&gt; &lt;SOAP-ENV:Header/&gt; &lt;SOAP-ENV:Body&gt; &lt;m:pingResponse xmlns:m="urn:tbs_blabla"&gt; &lt;m:ok xsi:type="xsd:boolean"&gt;true&lt;/m:ok&gt;&lt;/m:pingResponse&gt; &lt;/SOAP-ENV:Body&gt;&lt;/SOAP-ENV:Envelope&gt; </code></pre> <p>So, everything looks good, but in chromium in the javascript console i always get <code>XMLHttpRequest cannot load http://xubuntu-02:10000/tbs_blabla. Origin http://xubuntu-02 is not allowed by Access-Control-Allow-Origin.</code>.</p> <p>Always i send a request just nothing happens on the webpage.</p> <p>I have no idea why. I tested many things. E.g. start chromium with <code>chromium-browser --disable-web-security</code> or with <code>chromium-browser --allow-file-access-from-files</code>.</p> <p>I checked many stackoverflow-posts:</p> <p><a href="https://stackoverflow.com/questions/5396527/error-origin-null-is-not-allowed-by-access-control-allow-origin-when-loading">Error: &quot;Origin null is not allowed by Access-Control-Allow-Origin&quot; when loading an XML file with JQuery&#39;s ajax method</a></p> <p><a href="https://stackoverflow.com/questions/3595515/xmlhttprequest-error-origin-null-is-not-allowed-by-access-control-allow-origin">XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin</a></p> <p><a href="https://stackoverflow.com/questions/8456538/origin-null-is-not-allowed-by-access-control-allow-origin">Origin null is not allowed by Access-Control-Allow-Origin</a></p> <p><a href="https://stackoverflow.com/questions/7752527/ajax-origin-null-is-not-allowed">$.ajax(): Origin null is not allowed</a></p> <p><a href="https://stackoverflow.com/questions/6114436/access-control-allow-origin-error-sending-a-jquery-post-to-google-apis">Access-Control-Allow-Origin error sending a jQuery Post to Google API&#39;s</a></p> <p>...</p> <p>Maybe someone can see what i am doing wrong?</p> <p>Thank you for the help.</p> <p>Best regards</p> <p>--edit--</p> <p>I just wrote a small 'proxy' in php. It just receives the xml sends it to localhost:10000 and then it returns the xml-answer. now i use the post-field data for the xml.</p> <p>Here is the php-file:</p> <pre><code>&lt;?php echo shell_exec('curl http://localhost:10000/tbs_lgrow -m60 -d' . escapeshellarg($_POST['data'])); ?&gt; </code></pre> <p>Now it works with this little hack.</p> <p>Thanks</p> <p>Best regards</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.
 

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