与头节点js的GET调用

这是我做一个REST调用的代码。 我已经尝试与POSTMANrest电话和url和标题是好的。 但是对于节点j,我无法做到这一点

我没有在这里给出真正的API密钥和url

/** * HOW TO Make an HTTP Call - GET */ // options for GET var optionsget = { host : 'abcd.com:80/edwde/wedwed/', // here only the domain name // (no http/https !) //port : 443, //path : '/youscada', // the rest of the url with parameters if needed headers : getheaders, method : 'GET' // do GET }; var getheaders = { 'x-api-key' : 'diudnwod87wedh8778=', 'content-type' : 'application/json;charset=UTF-8' }; console.info('Options prepared:'); console.info(optionsget); console.info('Do the GET call'); // do the GET request var reqGet = https.request(optionsget, function(res) { console.log("statusCode: ", res.statusCode); // uncomment it for header details console.log("headers: ", res.headers); res.on('data', function(d) { console.info('GET result:\n'); process.stdout.write(d); console.info('\n\nCall completed'); }); }); reqGet.end(); reqGet.on('error', function(e) { console.error(e); }); 

这是我的代码的参考: http : //isolaso​​ftware.it/2012/05/28/call-rest-api-with-node-js/

我编辑了我的代码,它正在工作:

 var http = require('http'); /** * HOW TO Make an HTTP Call - GET */ // options for GET var getheaders = { 'x-api-key' : 'diudnwod87wedh8778=', 'content-type' : 'application/json;charset=UTF-8' }; var optionsget = { host : 'abcd.com', // here only the domain name // (no http/https !) port : 80, path : '/edwde/wedwed/', // the rest of the url with parameters if needed headers : getheaders, method : 'GET' // do GET }; console.info('Options prepared:'); console.info(optionsget); console.info('Do the GET call'); // do the GET request var reqGet = http.request(optionsget, function(res) { console.log("statusCode: ", res.statusCode); // uncomment it for header details console.log("headers: ", res.headers); res.on('data', function(d) { console.info('GET result:\n'); process.stdout.write(d); console.info('\n\nCall completed'); }); }); reqGet.end(); reqGet.on('error', function(e) { console.error(e); }); 

什么是输出完全? 另外,在实际声明了getheaders之前,你可以在optionsget中引用getheaders。

您应该查看请求库。