Asked by:
http request from server to client

Question
-
User1448655074 posted
Hi All
I'm running a kiosk type setup and need to check if a certain application is running on the client from my server.
Server is on c# asp.net
The only way of checking that is by running a http request to the client using
http://<clientIP:9192>/omxcmd?cmd=position
All my clients are connected to the server via vpn so I can just use the IP of the client.
Currently I have tried doing this using ajax with the below but I'm getting errors around cross domain which despite my efforts cannot resolve... see https://stackoverflow.com/questions/51235842/http-request-with-javascript-ajax-no-access-control-allow-origin
$.ajax({ url: "http://VPNIPofCLIENT:9192/omxcmd?cmd=position", type: "GET", crossDomain: true, dataType: "json", success: function (response) { var resp = JSON.parse(response) alert(resp.status); }, error: function (xhr, status) { alert("error"); } });
The return value is just a text/string
This does seem off as its a http request from the server to the client and not the other way round
I could probably do this from code-behind in c# and use curl or something but would rather do this on the client side if possible...
If there anything I can do to get this?
Monday, July 9, 2018 2:27 PM
All replies
-
User-369506445 posted
hi
what is the <g class="gr_ gr_89 gr-alert gr_spell gr_inline_cards gr_run_anim ContextualSpelling" id="89" data-gr-id="89">omxcmd</g> exactly? what kind of technology do you <g class="gr_ gr_19 gr-alert gr_gramm gr_inline_cards gr_run_anim Style multiReplace" id="19" data-gr-id="19">use ?</g>
Monday, July 9, 2018 2:58 PM -
User-1171043462 posted
Try the dynamic script technique for Cross Domain calls work.
Comment your AJAX call and put this
//Create a SCRIPT element. var script = document.createElement("script"); //Set the Type. script.type = "text/javascript"; //Set the source to the URL the JSON Service. script.src = 'http://VPNIPofCLIENT:9192/omxcmd?cmd=position&callback=OnSuccess'; //Append the script element to the HEAD section. document.getElementsByTagName("head")[0].appendChild(script);
And then add this function
function OnSuccess(response) { var resp = JSON.parse(response) alert(resp.status); }
Monday, July 9, 2018 5:17 PM -
User1448655074 posted
this is real close
gives the same error as my original ajax call or with using jsonp
Uncaught SyntaxError: Unexpected identifier
omxcmd?cmd=position&callback=
OnSuccess:1 Uncaught SyntaxError: Unexpected identifier return value if successful should be "no player"
Monday, July 9, 2018 5:58 PM -
User-1171043462 posted
Which line is throwing error? Can you please debug in Visual Studio?
Monday, July 9, 2018 6:21 PM -
User1448655074 posted
thanks Mudassar I managed to resolve this by using a webservice (asmx) which containted the http get request and then calling the webmethod using ajax
Ideally I wanted a pure client side solution using jquery/javascript but this will have to do....
Tuesday, July 17, 2018 2:53 PM