-
• #2
Got it, you need to specify an undocumented parameter in options called
protocol
, and set it tohttps:
(note the trailing colon).var options = { host: 'google.com', protocol: 'https:', port: 443, path: '/', method: 'GET', };
-
• #3
Thanks - I've just updated the docs, so it'll be on the main site next time I update
-
• #4
I want to make a PUT HTTPS request with the Espruino WiFi module. How can I do this? Require("https") is not recognised. Can someone give me an example code?
-
• #5
Hi!
You can try something like this:
// Load the WiFi and HTTP modules var wifi = require("Wifi"); var https = require("http"); // Your WiFi credentials var SSID = "your-SSID"; var PASSWORD = "your-password"; // Connect to WiFi wifi.connect(SSID, { password: PASSWORD }, function(err) { if (err) { console.log("WiFi connection error: ", err); return; } console.log("Connected to WiFi"); // Options for the HTTPS request var options = { host: "your-server.com", port: 443, path: "/your-endpoint", method: "PUT", headers: { "Content-Type": "application/json", "Content-Length": JSON.stringify({ data: "your-data" }).length } };
-
• #6
Hello,
I succeeded in making an HTTPS request but after a few attempts, I get the messag below. Anyone who can help me with this?
1 Attachment
-
• #7
Sorry to hear that - that could be a sign that you're running low on memory as HTTPS can take a lot.
Do you think it's possible that maybe you're not closing the HTTPS connection, so it's staying open? So then multiple HTTPS connections open at the same time would chew through your RAM.
You could check
process.memory().usage
to see if the free memory is going down after each call, or if it's staying constant (which is what you want really)
In the docs I can see there is provision for HTTPS when using
http.get
, you just pass ahttps://
url and it works it out. But what about when usinghttp.request
?Works fine, but if I change the port to 443 it just stalls. I assume because its trying to talk HTTP to a HTTPS port. I don't really want to use
tls.connect
because that gives me a socket rather than a https connection.