Andalousie
Andalousie

Reputation: 11

Post request working on web simulator but not on the app

i am making a tizen application for samsung gear s3 and im trying to send a post request using javascript when i launch my application on the web simulator the request work fine but when i launch the app on my device the request doesnt work

I added the internet privilege on the config.xml

    <script type="text/javascript">
     function send(){
        console.log("1");
        var data = "<m2m:>";

        var xhr = new XMLHttpRequest();
        xhr.withCredentials = true;

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

        xhr.open("POST", "http://127.0.0.1:8081/~/in-cse/in-name/MY_SENSOR/DATA");
        xhr.setRequestHeader("X-M2M-Origin", "admin:admin");
        xhr.setRequestHeader("Content-Type", "application/xml;ty=4");
        xhr.setRequestHeader("cache-control", "no-cache");

        xhr.send(data);
        console.log("end");
    }
    </script>

for the result my server need to add the m2m on his side, but thats something relevent because its working on postman

I think its a issue with the cors policy, do you know how i can fix that?

Thanks for your time

Upvotes: 0

Views: 145

Answers (1)

15kokos
15kokos

Reputation: 698

I did some research about this topic and it seems to me that you need to add the access domain in config.xml of your application. Guide says that adding:

<access origin="http://127.0.0.1:8081/~/in-cse/in-name/MY_SENSOR/DATA" subdomains="true"/>

should help with this problem. You can also find more information about CORS on Tizen

Upvotes: 1

Related Questions