I'm trying to interact with NMControl's RPC server from Javascript, but I'm not having much luck. Based on code found via Google (i.e. probably crappy code), I have the following:
Code: Select all
var http = new XMLHttpRequest();
var url = "http://127.0.0.1:9000/";
var params = {method: "data", params: ["getValue", "d/dot-bit"], id: 1};
http.open("POST", url, false);
//Send the proper header information along with the request
http.setRequestHeader("Content-type", "text/x-json");
http.setRequestHeader("Content-length", params.length);
http.setRequestHeader("Connection", "close");
http.send(JSON.stringify(params));
Unfortunately, when I execute this code, the XMLHttpRequest never returns from send(), and NMControl says this:
Code: Select all
ValueError: No JSON object could be decoded
Using Wireshark, I don't see any HTTP headers when NMControl talks to itself, whereas my Javascript code is sending HTTP headers. I assume this is related to the issue. Does NMControl not use HTTP requests? Is there a preferred way to speak this protocol in Javascript?
Thanks.
Jeremy Rand, Lead Namecoin Application Engineer
NameID:
id/jeremy
DyName: Dynamic DNS update client for .bit domains.
Donations: BTC 1EcUWRa9H6ZuWPkF3BDj6k4k1vCgv41ab8 ; NMC NFqbaS7ReiQ9MBmsowwcDSmp4iDznjmEh5