Sending http request in node.js

后端 未结 1 1122
-上瘾入骨i
-上瘾入骨i 2020-12-09 08:57

I am trying to send a http request to a neo4j database using node.js. This is the code I am using:

var options = {
        host: \'localhost\',
        port:         


        
相关标签:
1条回答
  • 2020-12-09 09:40

    If it's a simple GET request, you should use http.get()

    Otherwise, http.request() needs to be closed.

    var options = {
        host: 'localhost',
        port: 7474,
        path: '/db/data',
        method: 'GET',
        headers: {
            accept: 'application/json'
        }
    };
    
    console.log("Start");
    var x = http.request(options,function(res){
        console.log("Connected");
        res.on('data',function(data){
            console.log(data);
        });
    });
    
    x.end();
    
    0 讨论(0)
提交回复
热议问题