From 6b1190dc1a0fa55bda4946c3c5fbde318b70828f Mon Sep 17 00:00:00 2001 From: Erin Kelkar Date: Wed, 26 Oct 2016 10:55:33 -0400 Subject: [PATCH] Change http to https to avoid problems since the request responds with a statusCode of 403 and a statusMessage of 'Moved Permanently'. Include spelling corrections proposed by tay in commit a0932af3d7a93dabb292944cc1faf7f0769e69e1.' --- .../HTTP/clients/how-to-create-a-HTTP-request/content.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pages/articles/HTTP/clients/how-to-create-a-HTTP-request/content.md b/pages/articles/HTTP/clients/how-to-create-a-HTTP-request/content.md index b7ca79d..b3dd419 100644 --- a/pages/articles/HTTP/clients/how-to-create-a-HTTP-request/content.md +++ b/pages/articles/HTTP/clients/how-to-create-a-HTTP-request/content.md @@ -3,7 +3,7 @@ Another extremely common programming task is making an HTTP request to a web ser As an example, we are going to preform a GET request to [www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new](www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new) (which returns a random integer between 1 and 10) and print the result to the console. - var http = require('http'); + var https = require('https'); //The url we want is: 'www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new' var options = { @@ -14,18 +14,18 @@ As an example, we are going to preform a GET request to [www.random.org/integers callback = function(response) { var str = ''; - //another chunk of data has been recieved, so append it to `str` + //another chunk of data has been received, so append it to `str` response.on('data', function (chunk) { str += chunk; }); - //the whole response has been recieved, so we just print it out here + //the whole response has been received, so we just print it out here response.on('end', function () { console.log(str); }); } - http.request(options, callback).end(); + https.request(options, callback).end(); Making a POST request is just as easy. We will make a POST request to `www.nodejitsu.com:1337` which is running a server that will echo back what we post. The code for making a POST request is almost identical to making a GET request, just a few simple modifications: