Reputation: 10219
I'm making the following request:
var options = {
host: "api.github.com",
port: 443,
path: "/repos/myusername/myreponame/issues",
headers: {Authorization: "Basic " + new Buffer(username + ":" + password).toString("base64")}
};
var request = http.get(options, function(response) {
response.on("data", function(data) {
console.log("data");
});
});
request.on("error", function(error) {
console.log(error);
});
This results in an error:
{ [Error: socket hang up] code: 'ECONNRESET' }
Any ideas why?
Upvotes: 3
Views: 923
Reputation: 10219
I figured this one out. I was using http
instead of https
. Here's the working code:
var https = require("https");
username = "myusername";
password = "mypassword";
var options = {
host: "api.github.com",
port: 443,
path: "/repos/myusername/myreponame/issues",
headers: {
"Authorization": "Basic " + new Buffer(username + ":" + password).toString("base64"),
"User-Agent": username
}
};
var request = https.get(options, function(response) {
response.on("data", function(data) {
process.stdout.write(data);
});
});
request.on("error", function(error) {
console.log(error);
});
Upvotes: 4