Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
743 views
in Technique[技术] by (71.8m points)

node.js - TypeError: Request path contains unescaped characters, how can I fix this

/*Making http request to the api (Git hub)
create request
parse responce
wrap in a function
*/
var https = require("https");

var username = 'lynndor';
//CREATING AN OBJECT
var options = {
    host: 'api.github.com',
    path: ' /users/'+ username +'/repos',
    method: 'GET'
};

var request = https.request(options, function(responce){
    var body = ''
    responce.on("data", function(chunk){
        body += chunk.toString('utf8')
    });
    responce.on("end", function(){
        console.log("Body", body);
    });
});
request.end();

Im trying to create a request to the git hub api, the aim is to get the list repository for the specified you, but i keep getting the above mentioned error, please help

question from:https://stackoverflow.com/questions/31024779/typeerror-request-path-contains-unescaped-characters-how-can-i-fix-this

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Your "path" variable contains space

path: ' /users/'+ username +'/repos',

Instead it should be

path: '/users/'+ username +'/repos',


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...