Hi Guys - having issues getting an HTTP POST to work. Device is an espruino wifi, flashed to the latest version.
Here's the code:
var WIFI_NAME = "xxxx";
var WIFI_OPTIONS = { password : "yyy" };
var wifi = require("EspruinoWiFi");
wifi.connect(WIFI_NAME, WIFI_OPTIONS, function(err) {
if (err) {
console.log("Connection error: "+err);
return;
}
console.log("Connected!");
sendData();
});
function sendData() {
var options = {
host: 'http://192.168.1.66', // host name
port: 8081, // (optional) port, defaults to 80
path: '/stats/login/', // path sent to server
method: 'POST',
headers: { "Content-type" : "application/json" }
};
var req = require("http").request(options, function(res) {
console.log('res',res);
res.on('error', function(data) {
console.log("error> "+data);
});
res.on('data', function(data) {
console.log("HTTP> "+data);
});
res.on('close', function(data) {
console.log("Connection closed");
});
});
req.end("{module:'espruino'}");
console.log("Request sent");
The connection works OK and I also get the 'request sent' message, but nothing after that on the espruino, and no connection received by the server.
I've verified that the endpoint (which is a server of mine) is working OK (accepts a POST from a REST client), and HTTP.GET works fine (copied one of the examples). I'm doubtless doing something basic wrong, but not sure how to debug further...
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.
Hi Guys - having issues getting an HTTP POST to work. Device is an espruino wifi, flashed to the latest version.
Here's the code:
The connection works OK and I also get the 'request sent' message, but nothing after that on the espruino, and no connection received by the server.
I've verified that the endpoint (which is a server of mine) is working OK (accepts a POST from a REST client), and HTTP.GET works fine (copied one of the examples). I'm doubtless doing something basic wrong, but not sure how to debug further...