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.
I just implemented a few test functions, e.g. a ping
-function which just returns an xml without any interesting data.
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.
Then i try to put the answer into a div
next to the send
-button. This html-file is on my local machine xubuntu-02
on an apache2 webserver.
Here is the code:
<HTML xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<HEAD>
<TITLE>Debug Post</TITLE>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript">
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');
}
});
}
</script>
</HEAD>
<BODY>
<H1>Debug Post</H1>
<textarea id="data" rows="10" cols="80">
<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/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <m:ping xmlns:m="urn:tbs_blabla"> <m:name xsi:type="xsd:string">Jonny B. Good</m:name></m:ping> </SOAP-ENV:Body></SOAP-ENV:Envelope>
</textarea>
<p>
<input type="button" value="Submit" onclick="submit_data();return false;" />
</p>
<p>
<div id="res">
</div>
</p>
</BODY>
</HTML>
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.
I also checked the request with wireshark, there it seems to be ok:
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
<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/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <m:ping xmlns:m="urn:tbs_blabla"> <m:name xsi:type="xsd:string">Jonny B. Good</m:name></m:ping> </SOAP-ENV:Body></SOAP-ENV:Envelope>
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
<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/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <m:pingResponse xmlns:m="urn:tbs_blabla"> <m:ok xsi:type="xsd:boolean">true</m:ok></m:pingResponse> </SOAP-ENV:Body></SOAP-ENV:Envelope>
So, everything looks good, but in chromium in the javascript console i always get XMLHttpRequest cannot load http://xubuntu-02:10000/tbs_blabla. Origin http://xubuntu-02 is not allowed by Access-Control-Allow-Origin.
.
Always i send a request just nothing happens on the webpage.
I have no idea why. I tested many things. E.g. start chromium with chromium-browser --disable-web-security
or with chromium-browser --allow-file-access-from-files
.
I checked many stackoverflow-posts:
XmlHttpRequest error: Origin null is not allowed by Access-Control-Allow-Origin
Origin null is not allowed by Access-Control-Allow-Origin
$.ajax(): Origin null is not allowed
Access-Control-Allow-Origin error sending a jQuery Post to Google API's
...
Maybe someone can see what i am doing wrong?
Thank you for the help.
Best regards
--edit--
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.
Here is the php-file:
<?php
echo shell_exec('curl http://localhost:10000/tbs_lgrow -m60 -d' . escapeshellarg($_POST['data']));
?>
Now it works with this little hack.
Thanks
Best regards