Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change http to https to avoid problems since the request responds wit… #99

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -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:
Expand Down