문제

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