Reputation: 52531
https
get request with https.get
const https = require("https")
https.get({
url: "https://api.github.com/users/ryanve/repos"
}, response => {
let data = ""
response
.on("data", chunk => data += chunk)
.on("end", () => {
console.log(data)
})
})
.on("error", e => {
console.error(e.message)
})
ECONNREFUSED
errorconnect ECONNREFUSED 127.0.0.1:443
What causes this error?
Authentication?
How do I fix?
node --version
is v12.16.2
Upvotes: 2
Views: 1211
Reputation: 52531
url
syntax. Thanks!curl
worked to same endpointUser-Agent
in options.headers
curl
curl -iH User-Agent:ryanve https://api.github.com/users/ryanve/repos
https.get
https.get("https://api.github.com/users/ryanve/repos", {
headers: {
"User-Agent": "ryanve"
}
}, response => {
let data = ""
response
.on("data", chunk => data += chunk)
.on("end", () => {
console.log(JSON.parse(data, null, 2))
})
})
.on("error", e => {
console.error(e.message)
})
Upvotes: 1
Reputation: 48592
You can't include url
in an object that you pass to get
. Since that's all you passed and it was ignored, it used a default URL of localhost. (IMO, having a default URL and not just throwing an error saying a URL is missing is a wart in NodeJS, but that's neither here nor there.) Replace this:
https.get({
url: "https://api.github.com/users/ryanve/repos"
}
With this:
https.get("https://api.github.com/users/ryanve/repos"
Upvotes: 1