This is 1 of my first times using the https node.js module and I tried to make a GET
request with this code
const url = new URL("valid url") //I did put a valid url
https.get({
host: url.hostname,
path: url.pathname,
headers: {
"Content-Type": "application/json"
}
}, (res) => {
res.setEncoding("utf8")
let str = ""
res.on("data", c => {
console.log(c)
})
res.on("end", () => {
console.log(str) //this was meant to log the data but I removed the "str += c" from the data callback
})
})
But this logs the following:
▼�
�VJ-*�/��LQ�210ЁrsS��‼�S����3KR§2�§�R♂K3�RS�`J�↕sA�I�)�♣�E@NIj�R-��♥g��PP
But I would think .setEncoding("utf8")
would work. Is it something to do with the headers? Or maybe the URL
object? The result I want is in a <pre>
element and is valid JSON.