Last active
September 14, 2019 11:21
-
-
Save CrackerHax/36e15a33c2dba2a970fd to your computer and use it in GitHub Desktop.
Sample JsonRPC code for highfidelity.io
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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