I'm trying to get a filtered record from loopback, but I don't understand why nodejs gives error on fallowing commands:
const https = require('https');
var uid = '02644da038b37d7ba70b7ee1a92ba1d9';
var URL = 'https://mobileapp.mydomain.com/api/uuids?filter[where][uuid]='+uid;
https.get(URL, (res) => {
console.log('statusCode:', res.statusCode);
console.log('headers:', res.headers);
res.on('data', (d) => {
process.stdout.write(d);
});
}).on('error', (e) => {
console.error('ERROR:',e);
});
the error on output:
ERROR: { Error: getaddrinfo ENOTFOUND mobileapp.mydomain.com mobileapp.mydomain.com:443
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:79:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'mobileapp.mydomain.com',
host: 'mobileapp.mydomain.com',
port: 443 }
Obviously the domain you used is not valid.
URL shouldn't contain https://
modify url from
var URL = 'https://mobileapp.mydomain.com/api/uuids?filter[where][uuid]='+uid; to var URL = 'mobileapp.mydomain.com/api/uuids?filter[where][uuid]='+uid;
I had this issue and this resolved it.
probably it's because of SSL authentication in loopback, can you please try this npm package
Related
I am trying to get a malformed HTTP response using node. Since the response is malformed, I cannot use request normally (it would give the HPE_INVALID_CONSTANT error)
From this answer https://stackoverflow.com/a/23543522/1748450 I can get the raw HTTP response using the net module like so:
var net = require('net');
var host = '192.168.1.1',
port = 80,
socket = net.connect(port, host, function() {
var request = "GET / HTTP/1.1\r\nHost: " + host + "\r\n\r\n",
rawResponse = "";
// send http request:
socket.end(request);
// assume utf-8 encoding:
socket.setEncoding('utf-8');
// collect raw http message:
socket.on('data', function(chunk) {
rawResponse += chunk;
});
socket.on('end', function(){
console.log(rawResponse);
});
});
However, this only works with getting the response from the host's root page (192.168.1.1). The page I'm trying to get the response from is actually 192.168.1.1/admin/landingpage.fwd.
If I try to edit host to that URL then I get this error:
events.js:187
throw er; // Unhandled 'error' event
^
Error: getaddrinfo ENOTFOUND 192.168.1.1/admin/landingpage.fwd
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:60:26)
Emitted 'error' event on Socket instance at:
at emitErrorNT (internal/streams/destroy.js:92:8)
at emitErrorAndCloseNT (internal/streams/destroy.js:60:3)
at processTicksAndRejections (internal/process/task_queues.js:80:21) {
errno: 'ENOTFOUND',
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: '192.168.1.1/admin/landingpage.fwd'
}
Is this possible to fetch this using the net module in the above example?
If not possible, what other way can I use to get the raw HTTP response from that URL?
You can just put the path in your http request as in:
var request = "GET /admin/landingpage.fwd HTTP/1.1\r\nHost: " + host + "\r\n\r\n",?
That's where the path goes in an http request.
I'm trying to run a very simple node file that used to work, but now I get this error.
events.js:160
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED 127.0.0.1:3002
at Object.exports._errnoException (util.js:1026:11)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1081:14)
The thing is that if I run another application in this port, there's no problem. Even If I change the port in the file, the error persists.
The code of the file:
var http = require('http');
var opcoes = {
hostname: 'localhost',
port: 3002,
path: '/',
method: 'post',
headers: {
'Accept': 'application/json',
'Content-type': 'application/json'
}
}
//Content-type
var html = 'nome=José'; //x-www-form-urlencoded
var json = { nome: 'José' };
var string_json = JSON.stringify(json);
var buffer_corpo_response = [];
var req = http.request(opcoes, function(res) {
res.on('data', function(pedaco) {
buffer_corpo_response.push(pedaco);
});
res.on('end', function() {
var corpo_responde = Buffer.concat(buffer_corpo_response).toString();
console.log(corpo_responde);
});
});
req.write(string_json);
req.end();
Your port in your code is 3005. Make sure they all share that number.
I'm running an express 4 app (nodejs)
In one of the server side functions, I want to make a GET request to get some value. The GET request url is pointing at the same server. Why this doesn't work and how do I make it work?
Extra info:
http://mywebsite/ is the main domain of my web app.
http://mywebsite/abc/getData/16-10-2017 works in the browser
Externally facing requests work fine (so no issue with request setup)
function testing(){
dateVAL="16-10-2017"
var requestURL = "http://mywebsite/abc/getData/" + dateVAL
request({
url: requestURL,
method:"GET",
},
function(error,response,body){
console.log("error")
console.log(error)
console.log("response")
console.log(response)
console.log("body")
console.log(body)
});
}
Error code:
{ Error: getaddrinfo ENOTFOUND mywebsite mywebsite:80
at errnoException (dns.js:28:10)
at GetAddrInfoReqWrap.onlookup [as oncomplete] (dns.js:76:26)
code: 'ENOTFOUND',
errno: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'mywebsite',
host: 'mywebsite',
port: 80 }
Found a solution, modified my address from:
var requestURL = "http://mywebsite/abc/getData/" + dateVAL
to:
var requestURL = "http://localhost/abc/getData/" + dateVAL
I did make a get request to an API but get an ECONNREFUSED Error. The problem is not the API because when I type it in a browser, I get back results in JSON.
This is my code;
var https = require("https");
var options = {
host : 'nairabox.com',
port : 443,
path : '/v1/tickets/auth=APIKEY&as=showtimes&cinemaId=CINEMAID&ticketId=TICKETID',
method : 'GET'
}
var req = https.request(options, function(res) {
res.on('data', function(data) {
console.log( JSON.parse(data));
});
});
req.end();
req.on('error', function(err){
console.log("Error: ", err);
});
This is the error;
Error: { Error: connect ECONNREFUSED 162.255.119.75:443
at Object.exports._errnoException (util.js:1022:11)
at exports._exceptionWithHostPort (util.js:1045:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1087:14)
code: 'ECONNREFUSED',
errno: 'ECONNREFUSED',
syscall: 'connect',
address: '162.255.119.75',
port: 443 }
Anyone can be kind enough to test it replacing the parameters with random numbers and you'd get the same error. How can I fix it. API gives results in the browser though.
The hostname nairabox.com resolves to two IP-numbers, 178.79.175.127 and 162.255.119.75. The latter is refusing connections, which is the issue you're running in to.
However, the host www.nairabox.com resolves to only one IP-number, 178.79.175.127, so I guess you should be using that hostname instead of the one without the www. prefix.
I am using node.js to download a zip folder from github's server. For some reason the code below works on any other network except for at work. Not sure it's a proxy or firewall issue slowing down the request causing a timeout.
var https = require('https');
var fs = require('fs');
var options = {
hostname : 'codeload.github.com',
port : 443,
path : '/wet-boew/wet-boew/zip/master',
method : 'GET'
};
var file = fs.createWriteStream("test_folder/master.zip");
var req = https.request(options, function(res) {
console.log("statusCode: ", res.statusCode);
console.log("headers: ", res.headers);
res.on('data', function(d) {
file.write(d);
});
});
req.end();
req.on('error', function(e) {
console.error(e);
});
This is the full error that is generated when running the above code on the network:
{ [Error: connect ETIMEDOUT] code: 'ETIMEDOUT', errno: 'ETIMEDOUT', syscall: 'connect' }
any work around ideas or help is appreciated, thanks!