JSON-RPC over HTTP?
#23
Thanks for the pointers Smile I took inspiration from your json-rpc webinterface and created this:

[HTML]<html>
<body>
<h1>Play Test</h1>
<script type="text/javascript">
var http_request = new XMLHttpRequest();
http_request.open( "POST", "jsonrpc", false );
http_request.send("{\"jsonrpc\": \"2.0\", \"method\": \"XBMC.Play\", \"params\": { \"file\": \"/home/arctic/8 - Sullivan Street.m4a\"}, \"id\": 1}");
</script>
</body>
</html>[/HTML]
I found this code works when I put it in a file called index.html, and stash that in a new webinterface addon directory: ~/.xbmc/addons/webinterface.example

It also needed an addon.xml in the webinterface.example directory:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<addon
  id="webinterface.example"
  version="0.1"
  name="example"
  provider-name="test">
  <requires>
    <import addon="xbmc.gui" version="2.11"/>
  </requires>
  <extension
    point="xbmc.gui.webinterface"/>
  <extension point="xbmc.addon.metadata">
    <summary>test</summary>
    <description>test</description>
    <platform>all</platform>
  </extension>
</addon>
I then had to configure my XBMC to use my new 'example' web interface and I could then use my phone to surf to my XBMC webpage. As soon as I opened it the file started playing.

That's great, but not quite what I want ...

I want to send a JSON command to XBMC from my phone. I want the code that does that to be on my phone too - not set as the web interface for XBMC (because that would be embarrassing :o).

I tried changing my open command from above to:
[HTML]http_request.open( "POST", "http://10.0.0.5:8080/jsonrpc", true, "username", "password" );
[/HTML]

Then tried running the html file directly - but this failed, though it still worked through the web interface.

I noticed while googling around a bit that I might have a problem doing that anyway:
Wikipedia Wrote:In the early development of the World Wide web, it was found possible to breach users' security by the use of JavaScript to exchange information from one web site with that from another less reputable one. All modern browsers therefore implement a same origin policy that prevents many such attacks, such as cross-site scripting. XMLHttpRequest data is subject to this security policy.

Any suggestions? Am I missing the point somehow? Should I try using jQuery like the default interface? but I'm guessing this will have the same problem for me though.

I'm mentally preparing myself to try something else ... most phones can run java apps ...
Reply


Messages In This Thread
JSON-RPC over HTTP? - by bradvido88 - 2010-12-20, 17:24
[No subject] - by _Andy_ - 2010-12-20, 17:59
[No subject] - by darkscout - 2010-12-20, 18:01
[No subject] - by bradvido88 - 2010-12-20, 18:17
[No subject] - by bradvido88 - 2010-12-20, 19:16
[No subject] - by Montellese - 2010-12-20, 20:42
[No subject] - by bradvido88 - 2010-12-20, 20:49
[No subject] - by darkscout - 2010-12-20, 21:51
[No subject] - by bradvido88 - 2010-12-20, 21:52
[No subject] - by plumser - 2010-12-21, 19:49
[No subject] - by Adam - 2011-01-01, 04:57
[No subject] - by Montellese - 2011-01-01, 11:46
[No subject] - by toenuff - 2011-01-04, 05:26
[No subject] - by toenuff - 2011-01-04, 05:45
[No subject] - by manxam - 2011-01-05, 09:17
[No subject] - by Montellese - 2011-01-05, 10:48
Actionscript 2.0 - by TheyKilledKenny - 2011-01-07, 13:18
[No subject] - by Montellese - 2011-01-07, 14:08
[No subject] - by TheyKilledKenny - 2011-01-07, 18:41
[No subject] - by Montellese - 2011-01-07, 20:27
[No subject] - by ArcticGiraffe - 2011-08-13, 02:08
[No subject] - by topfs2 - 2011-08-13, 10:40
[No subject] - by ArcticGiraffe - 2011-08-13, 15:32
[No subject] - by topfs2 - 2011-08-13, 18:48
[No subject] - by ArcticGiraffe - 2011-08-13, 19:27
RE: JSON-RPC over HTTP? - by Richard6360 - 2016-05-22, 11:38
Logout Mark Read Team Forum Stats Members Help
JSON-RPC over HTTP?1