1

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:

Error: "Origin null is not allowed by Access-Control-Allow-Origin" when loading an XML file with JQuery's ajax method

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

Community
  • 1
  • 1
Kevin Meier
  • 2,339
  • 3
  • 25
  • 52
  • you should specify somewhere on http://xubuntu-02:10000/tbs_lgrow or a config file (sorry I never worked with nanohttpd) the access origin policy. E.g.: in php this would be to add header('Access-Control-Allow-Origin: *'); to the file (tbs_lgrow) – xtds Mar 10 '13 at 12:52
  • Ups, sry i forgot to change everywhere `tbs_lgrow` (original name) to `tbs_blabla`. I did this now. I try to change this in `nanohttp`. – Kevin Meier Mar 10 '13 at 13:03
  • Hm, libcsoap doesn't seem to give the possibility to add /edit the headers for the http response. So i think i have no chance to do this without remcompiling the libcsoap package and include a line to add this header. :-/ So there isn't another way to do this? Maybe a browser config or something like that? – Kevin Meier Mar 10 '13 at 13:11
  • http://www.w3.org/Protocols/rfc2616/rfc2616-sec7.html#sec7.1 stated in http://read.pudn.com/downloads100/sourcecode/unix_linux/network/406956/nanohttp/nanohttp-common.h__.htm maybe something with HEADER_ALLOW? – xtds Mar 10 '13 at 13:12
  • the browser config looks fine (--disable-web-security and CORS so), maybe we're missing something, have u tried another browser (the header is indeed not necessary if you can fix it with browser, for local testing etc.) – xtds Mar 10 '13 at 13:39
  • Thx for the infos. I tried to play with the HEADER_ALLOW, but i didnt get any useful results. (Maybe i did something wrong?). I tested some different browsers: Opera on the same pc just does nothing, the request works and the output of the js-console is ok. I can also see the response with the dev-tools, but the js never calls the `success` or `fail` function. Firefox does nothing, in the dev tools there is no response for the request shown. I tested chromium and firefox on another pc and i got the same results. – Kevin Meier Mar 10 '13 at 16:58

0 Answers0