0

I am trying to send a request to HTTPS url in my case it is the updateDataUrl which is the https url but i want to skip the ssl certificate for now when sending request since we are waiting for the domain to be purchased.How can I send the https request by passing the ssl certificate to this url .Below is the code that I have tried seeing some solutions on stackoverflow but it does not work for me.

var XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest; 
var https = require('https');
var app = express();
const { constants } = require('crypto')

app.post('/updateData, function (req, res) {


var xhr = new XMLHttpRequest();

xhr.open("POST", updateDataUrl, false);


xhr.onload = function () {
    var response = xhr.responseText;

    res.send(“Data Updated\n”);

};

xhr.onerror = function () {
         
    res.send(null);
};
xhr.send(updateData);
  });

https.createServer({
   secureOptions: constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1

 }, app).listen(443)
Organik Street
  • 103
  • 1
  • 3
  • 10
  • Since `xmlhttprequest` does not provide a way to do this and uses `https.request` in the background, this should help: https://stackoverflow.com/a/21961005/9779577 – Kunal Kukreja Aug 29 '20 at 18:31
  • Just curious, why not use something more up to date and feature-rich like [```axios```](https://www.npmjs.com/package/axios) ? ```xmlhttprequest``` is unmaintained, last publish is 5 years ago – Ramaraja Aug 29 '20 at 19:26
  • @Kunal will not that disable HTTPS / SSL / TLS checking across entire node.js environment,I just need to do it for this particular request. – Organik Street Aug 30 '20 at 05:36
  • @OrganikStreet I did mention that `xmlhttprequest` does not support this. The answer gives a hack of changing the environment variable along with a secure way to do this (using `request` module). You should use the **secure** option. – Kunal Kukreja Aug 30 '20 at 08:37

0 Answers0