在node.js中发送http请求 [英] Sending http request in node.js
问题描述
我正在尝试使用node.js向neo4j数据库发送http请求。这是我正在使用的代码:
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: 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);
});
});
我检查数据库是否正在运行(我连接到管理网页,一切正常) 。我担心问题不在数据库端,而是在node.js端。
I check out that the database is running (I connect to the administration web page and everything is working). I am afraid that the problem is not on the database side but on the node.js side.
我希望有些人可以对这个问题有所了解。我想学习如何在node.js中发送http请求,答案不必特定于neo4j问题。
I hope some could give some light about this issue. I want to learn how to send a http request in node.js, the answer does not have to be specific to the neo4j issue.
提前致谢
推荐答案
如果这是一个简单的GET请求,你应该使用 http.get()
If it's a simple GET request, you should use http.get()
否则, http.request()
需要关闭。
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();
这篇关于在node.js中发送http请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!