سؤال

On a Grunt-init template I would like to create a node.js https request. Is that possible?

Grunt-init console says: Warning: Protocol:https: not supported

Here is the code I am trying to add

var http = require('http');
var fs = require('fs');

var file = fs.createWriteStream("file.txt");
var request = http.get("https://someurl.com/file.text", function(response) {
  response.pipe(file);
});

Thanks.

هل كانت مفيدة؟

المحلول

You want the https module. It acts just like the http module, with a few differences that only matter when you want to check certs. See the node https docs for details.

In your example you can just replace require('http') with require('https').

You probably don't want to worry about which protocol to use for every url you want to fetch, so you might want to look into a higher level library: the request library is very popular, although there are many others.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top