Make sure to add the appropriate headers when sending JSON data:
var data = JSON.stringify({ key: "value" }); const options = { //... headers: { "Content-Type": "application/json", "Content-Length": json.length } }; require("http").request(options, function(res) { //... }).end(data);
I recommend attaching an error handler :)
const req = require("http").request(/* ... */); req.on("error", err => console.log("Request error: " + err.message)) ; req.end(data);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Make sure to add the appropriate headers when sending JSON data:
I recommend attaching an error handler :)