3 examples of 'javascript https request' in JavaScript

Every line of 'javascript https request' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your JavaScript code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
41function httpsRequest(options, callback) {
42 var request = https.request(options, function(response) {
43 var body = '';
44 response.on('data', function(chunk) {
45 body += chunk;
46 });
47 response.on('end', function() {
48 callback(body);
49 });
50 });
51 request.end();
52}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

251function request(options, data, callback) {
252// console.log(options);
253// console.log(data);
254 var os = options["outputStream"];
255 delete options["outputStream"];
256
257 var self = this, req = https.request(options);
258
259 req.on("response", function(response) {
260 var info = "";
261
262 response.on("end", function() {
263 var res = this, ret = {};
264 ret.statusCode = res.statusCode;
265 ret.status = http.STATUS_CODES[res.statusCode];
266 ret.data = info;
267 callback.call(self, null, ret);
268 });
269 response.on("close", function() {
270 response.emit("end");
271 });
272
273 if(os)
274 return response.pipe(os);
275
276 response.setEncoding("utf8");
277
278 response.on("data", function(data) {
279 info += data;
280 });
281 });
282
283 req.on("error", function(err) {
284 callback.call(self, err);
285 });
286
287 req.end(data);
288};
88function get (url, callback) {
89 https.get(url, function onResponse (res) {
90 if (res.statusCode !== 200) {
91 callback(new Error('got status code ' + res.statusCode + ' from ' + URL))
92 } else {
93 getBody(res, true, callback)
94 }
95 })
96}

Related snippets