我正在提出以下请求:
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);
});
这会导致错误:
{ [Error: socket hang up] code: 'ECONNRESET' }
任何想法为什么?
答案 0 :(得分:3)
我想出了这个。我使用的是http
而不是https
。这是工作代码:
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);
});