How does node.js send a get request with a request header?

http.get("url",function(res){
        
       var html = ""
        
       res.on("data",function(chunk){
              html += chunk
       })
       
       res.on("end",function(){
              console.log(html)
       })
       
})



//
const options = {
     url:"xxxx"
     a:"asdsaf",
     fsa:"asioduioasd"
}
http.get(options,function(res){
...
})

I want to send a request with a specific request header to the url address. Excuse me, how can I set the request header in this?


Please see document :

set headers object in options

< hr >
const options = {
     url:'xxxx'
     headers:{
         a:'asdsaf',
         fsa:'asioduioasd'
     }
}
< hr >

clipboard.png

clipboard.png


const options = {
    hostname: 'xxx', 
    port: xx, 
    path: xxx, 
    method: 'GET',
    headers:{
         a:'asdsaf',
         fsa:'asioduioasd'
     }
}
Menu