Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialNicholas Palenchar
784 Pointshttp.get returns no data or "301 Moved Permanently"
The http.get request returns no data below. If I change the argument in http.get to "http://www.teamtreehouse.com/"+username"+".json, I get data with a 301 Moved Permanently Code. What am I doing wrong?
Code below:
var http = require('http');
var username = 'chalkers';
function printMessage(username, badgeCount, points) {
var message = username + " has " + badgeCount + " total badge(s) and " + points + " points in JavaScript.";
console.log(message);
}
//connect to the API URL (https://teamtreehouse.com/username.json)
var request = http.get('http://teamtreehouse.com/'+username+'.json', function(response){
var body = "";
response.on('data', function(chunk) {
body += chunk;
console.log(chunk);
});
response.on('end', function() {
console.log(body);
});
});
//Read the data
//Parse the data
//Print the data
request.on('error', function(e){
console.error(e.message);
});
1 Answer
Julian Aramburu
11,368 PointsHi Nicholas!
Yesterday Treehouse implemented HTTPS on its website! So you must fix your request in order to work properly! Just modify http with https!
You can read more on this here!
Regards,