I am working on a project that requires https get and post methods. I have a short https.get function working here ...
const https = require("https"); function get(url, callback) { "use-strict"; https.get(url, function (result) { var dataQueue = ""; result.on("data", function (dataBuffer) { dataQueue += dataBuffer; }); result.on("end", function () { callback(dataQueue); }); }); } get("https://example.com/method", function (data) {
My problem is that there is no https.post, and I already tried the http solution here with the https module. How to make an HTTP POST request in node.js? but returns console errors.
I had no problems using get and post with Ajax in my browser with the same api. I can use https.get to send request information, but I donβt think it will be the right way, and I donβt think it will work with sending files later if I decide to expand.
Is there a small example with minimal requirements to do https.request, what will https.post be, if any? I do not want to use npm modules.
source share