Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[om2m-dev] Cannot send HTTP request from html file

Hello everyone,

My team and I are students at INSA Toulouse, working on a project using OM2M.
I am trying to send a simple HTTP GET request from an html file (as a user interface).
Here is the code snippet exported from postman that is supposed to send the request :

... (awesome) html content before ;) ...

<script type="text/_javascript_">

            function sendRequest() {
                $("#req_res").html("--");
                var data = "">
                var xhr = new XMLHttpRequest();
                xhr.withCredentials = true;

                xhr.addEventListener("readystatechange", function () {
                  if (this.readyState === 4) {
                    console.log(this.responseText);
                  }
                });

                xhr.open("GET", "http://127.0.0.1:8080/~/in-cse");
                xhr.setRequestHeader("x-m2m-origin", "admin:admin");
                xhr.setRequestHeader("accept", "application/xml");
                xhr.setRequestHeader("cache-control", "no-cache");
                xhr.setRequestHeader("postman-token", "3ae1710c-2bb0-2085-9e5e-204486399d93");

                xhr.send(data);
            }
</script>

... html ...

On postman, this request seems to work perfectly, but when I try to send it with XMLHttpRequest(), I get the following error in the web console :

XMLHttpRequest cannot load http://127.0.0.1:8080/~/in-cse. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 400.

I tried also with AJAX but could not find any solution either.
I am searching for a long time on the web trying to get rid of this but I could not find any help. I tried so many different things that I am a bit lost right now.
Does anyone know how to deal with this kind of issue?

Thank you in advance from the whole team!

Paul Guirbal

Back to the top