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!
Related
I am using this code to connect to a 3rd party server via HTTP GET. Locally on my MacOS this script works perfectly and I get statusCode:200 together with a valid message from the server. Am I missing something which should be added to this request when connecting from AWS?
const https = require("https");
var fs = require("fs");
var httpsAgent = require("https-agent");
var agent = httpsAgent({
pfx: fs.readFileSync("certs/test.com.pfx"),
passphrase: "xxxxxx",
rejectUnauthorized: true,
//enableTrace: true,
ca: fs.readFileSync("certs/ca-bundle.pem"),
});
const path = "/testapp?application=TEST&method=send&message=TEST"
const options = {
hostname: "test.server.com",
port: 443,
path: path,
method: "GET",
agent: agent,
};
''
console.log("Connecting to: https://test.server.com" + path)
const req = https.request(options, (res) => {
console.log(`statusCode: ${res.statusCode}`);
res.on("data", (d) => {
process.stdout.write(d);
});
});
req.on("error", (error) => {
console.error(error);
});
req.end();
Issue Solved: Issue was actually not related to SSL. Packet was being reject to invalid MTU size. Adjusted MTU value and worked as expected.
I'm trying to make a https request to an api of my work using node.js through the following script
const https = require('https');
const options = {
hostname,
path: fullPath,
port: 80,
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': data.length
}
};
const req = https.request(options, (res) => {
console.log('statusCode:', res.statusCode);
res.on('data', chunk => console.log('chunk:', chunk));
});
req.on('error', error => {
console.log('Failed!');
console.log(error);
});
req.write(data);
req.end();
And as a response i get
Failed!
Error: write EPROTO 6772:error:1408F10B:SSL routines:ssl3_get_record:wrong version number:c:\ws\deps\openssl\openssl\ssl\record\ssl3_record.c:332:
at WriteWrap.onWriteComplete [as oncomplete] (internal/stream_base_commons.js:87:16) {
errno: 'EPROTO',
code: 'EPROTO',
syscall: 'write'
}
I made this request on a browser using jQuery and it worked
$.post({
url, data,
success: res => console.log(res),
});
I tryed to use the header X-SSL-PROTOCOL with no success.
The url and data are hidden because they are confidential, but they are the same in the jQuery example and in node.js.
port: 80,
method: 'POST',
...
const req = https.request(options, (res) => {
You are using HTTPS against port 80, which is usually plain HTTP. The response you get suggest that the server is not providing HTTPS on this port, which is actually the expected behavior. HTTPS is instead usually done on port 443.
I made this request on a browser using jQuery and it worked
It is unclear what url is in this example but if it just was https://domain/path then port 443 was used. Port 80 would have only been used with HTTPS if explicitly given, i.e. https://domain:80/path.
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 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
I am trying out a NodeJS sample file from a tutorial as I am new to NodeJS but I just can't make it work. I get an error when I run below code:
var https = require("https");
var fs = require("fs");
var options = {
hostname: "en.wikipedia.org",
port: 443,
path: "/wiki/George_Washington",
method: "GET",
}
var req = https.request(options, function(res){ });
req.on('error', function(e) {
console.log(`here comes the error ${e}`);
});
I get the following error:
here comes the error:
Error:101057795:error:140770FC:SSLroutines:SSL23_GET_SERVunknownprotocol:openssl\ssl\s23_clnt.c:794:
I am clueless, I appreciate your help and insight :)
Update: Code had to be modified to go through a proxy server. I posted the solution and findings.
I solved the issue. Here is a summary of the problem and the solution that worked for me.
I ran this code in another network and it worked fine. So I realized the issue is that I am running the code behind our corporate web proxy and I need to modify my code to go through the proxy system instead of making a direct connection to target web server. I tried to install https-proxy-agent module but it failed to install. Again, because I am behind the proxy system. There is a npm config settings file named .npmrc file which can be found under C:/users/[YOUR_USER]. I added below configs to .npmrc to be able to install new packages as was advised Here.
proxy = http://172.26.128.35:3128/
https_proxy = http://172.26.128.35:3128/
strict-ssl = false
ca = null
registry = http://registry.npmjs.org/
Finally I modified my code as below to make it go through and the proxy system and voila~, It worked like a charm. If you encountered this issue, I hope this helps.
var https = require("https");
var fs = require("fs");
var HttpsProxyAgent = require('https-proxy-agent');
var proxy = 'http://172.26.128.35:3128';
var agent = new HttpsProxyAgent(proxy);
var options = {
hostname: "en.wikipedia.org",
port: 443,
path: "/wiki/George_Washington",
method: "GET",
agent: agent
}
var req = https.request(options, function(res) {
console.log(res.statusCode);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.log(`here comes the error ${e}`);
});
Have you tried this code?
var https = require("https");
var fs = require("fs");
var options = {
hostname: "en.wikipedia.org",
port: 443,
path: "/wiki/George_Washington",
method: "GET",
}
var req = https.request(options, function(res) {
console.log(res.statusCode);
res.on('data', function(d) {
process.stdout.write(d);
});
});
req.end();
req.on('error', function(e) {
console.log(`here comes the error ${e}`);
});
Works fine for me!