Skip to content

Instantly share code, notes, and snippets.

@CrackerHax
Last active September 14, 2019 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CrackerHax/36e15a33c2dba2a970fd to your computer and use it in GitHub Desktop.
Save CrackerHax/36e15a33c2dba2a970fd to your computer and use it in GitHub Desktop.
Sample JsonRPC code for highfidelity.io
function post(method,params)
{
var r_txt ='{"jsonrpc":"2.0","method":"'+method+'","params":{'+params+'},"id":1234}';
var http = new XMLHttpRequest();
http.open("POST", 'http://foo.com:8082', true);
http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
http.setRequestHeader("Content-length", r_txt.length);
http.setRequestHeader("Connection", "close");
http.onreadystatechange = function() {
if (http.readyState == 4) {
if (http.status == 200) {
var obj = JSON.parse(http.responseText);
// read the response here
print(JSON.stringify(obj));
}
else {
print("http error:"+http.status);
}
}
}
http.send(r_txt);
}
//Then format the method and parameters and post it like this:
var query='"name":"Foobar","Hobbies":"Long walks on the beach.","Age":69';
post("foobarMethod",query);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment