Page 1 of 1

Access web-api client from evothing client

Posted: 01:57, 10 Mar 2015
by evothingsuser
Hi,
I am running web-api in my local machine. The Evothings workbench is also launched in the local machine.
When i try to access the web-api URL from my iphone, looks like the webapi is not getting called. Let me know if you can provide me a sample to access web -api from evothings client?

Web-api url : http:/localhost:8080/test/evothings

I have modified index.html to make web-api request using jquery.

Note: the html page is able to make a web-api call and receive response when running outside the evothings work-bench.

Re: Access web-api client from evothing client

Posted: 10:34, 10 Mar 2015
by ardiri
http://localhost:8080/test/evothings

when running on your mobile device (evothings client) is obviously going to try to connect to localhost (127.0.0.1) - you may want to put the IP address of the desktop/laptop where you are running your webserver. your workbench and client have two different ip addresses. you can see the IP address of your workbench within the workbench itself which will be like http://192.168.0.x:4042/ - you need to extract the 192.168.0.x out of it.

Re: Access web-api client from evothing client

Posted: 15:11, 31 Mar 2016
by NiklasBrown
Hi,

I am also trying to post a JSON file to a localhost server (XAMPP). From the index.html file on the computer its working fine, but I cannot connect to the server with the $.POST Method from the Evothings Client. (I am currently working with EvothingsWorkbench 2.0 and Evothings Viewer).
I think it is related to the answer above, but I donĀ“t quite understand the reply by ardiri.
How does the url have to be defined when contacting a local server from the Viewer?
I tried nearly every combination- so many thanks for help!

Here is my post code:

Code: Select all

var url = "http://localhost/php/Test/testJSON.php";
        $.post(url, {json : JSON.stringify(actObject), name: dateiname}, function(data){
               
               console.log(data);
               alert('Success');
               }, alert('Not working')
                              );
                             

Re: Access web-api client from evothing client

Posted: 09:51, 26 Apr 2016
by alex
It's probably due to the cross-protocol violation as Evothings Studio runs https only.
Getting a resource via ajax then also needs to be the same protocol, to prevent stoppage.

There are two main strategies; either switch to https where available (free certs nowadays at [url]letsencrypt.org[/url]), or by using the CordovaHTTP plug-in which fetches known resources outside of the web container (the Evothings Viewer app has the plug-in installed). It looks similar to a regular JSON call:

Code: Select all

// Function to retrieve data, placing it in a "response" object if the plug-in is installed
function getJSON() {
        if (window.cordova) {
            cordovaHTTP.get( mSensorDataURL,
                function (response) {
                    if (response) {
                        sensor.data = JSON.parse(response.data);
                        doSomethingUsefulHere();
                    }
                },
                function (error) {
                    console.log(JSON.stringify(error));
                }
            );
        }



Read more about how to go about it here:
https://evothings.com/evothings-secured ... ver-https/