简体   繁体   中英

Cannot POST with ESP8266 (espruino)

I cannot make post request (get works fine) with espruino. I've already checked the documentation and it seems pretty equal here is my code:

let json = JSON.stringify({v:"1"});

let options = {
    host: 'https://******,
    protocol: 'https',
    path: '/api/post/*****',
    method: 'POST',
    headers:{
      "Content-Type":"application/json",
      "Content-Length":json.length
    }
  };

let post = require("http").request(options, function(res){
  res.on('data', function(data){
    console.log('data: ' + data);
  });
  res.on('close', function(data){
    console.log('Connection closed');
  });
});

post.end(json);

The espruino console only return the 'connection closed' console.log. The node.js server console (hosted on heroku and tested with postman) dont return anything. Obv the esp8266 is connected to the network

you're using a package called "http" and then trying to send a request over https. You should also log out 'data' in the res.close so you can get some errors to work with.

What you're doing looks fine (an HTTP Post example is here ), however Espruino doesn't support HTTPS on ESP8266 at the moment (there isn't enough memory on the chips for JS and HTTPS).

So Espruino will be ignoring the https in the URL and going via HTTP. It's possible that your server supports HTTP GET requests, but POST requests have to be made via HTTPS which is why it's not working?

If you did need to use HTTPS with Espruino then there's always the official Espruino WiFi boards, or I believe ESP32 supports it fine too.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM