Get Reqeust fails with Error: connect ECONNREFUSED
I'm trying to send a get request to the server. But I'm getting the following error, any idea how to avoid the error?
the error:
events.js:183
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED ******
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
my request:
var https = require("https");
// Update these options with the details of the web service you would like to call
var options = {
method: 'GET',
uri: 'https:*****',
resolveWithFullResponse: true,
json: true
};
var req = https.request(options, res => {
res.setEncoding('utf8');
var returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ' + JSON.stringify(returnData))
var pop = JSON.parse(returnData).population;
callback(pop);
});
});
req.end();
javascript node.js get-request
add a comment |
I'm trying to send a get request to the server. But I'm getting the following error, any idea how to avoid the error?
the error:
events.js:183
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED ******
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
my request:
var https = require("https");
// Update these options with the details of the web service you would like to call
var options = {
method: 'GET',
uri: 'https:*****',
resolveWithFullResponse: true,
json: true
};
var req = https.request(options, res => {
res.setEncoding('utf8');
var returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ' + JSON.stringify(returnData))
var pop = JSON.parse(returnData).population;
callback(pop);
});
});
req.end();
javascript node.js get-request
add a comment |
I'm trying to send a get request to the server. But I'm getting the following error, any idea how to avoid the error?
the error:
events.js:183
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED ******
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
my request:
var https = require("https");
// Update these options with the details of the web service you would like to call
var options = {
method: 'GET',
uri: 'https:*****',
resolveWithFullResponse: true,
json: true
};
var req = https.request(options, res => {
res.setEncoding('utf8');
var returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ' + JSON.stringify(returnData))
var pop = JSON.parse(returnData).population;
callback(pop);
});
});
req.end();
javascript node.js get-request
I'm trying to send a get request to the server. But I'm getting the following error, any idea how to avoid the error?
the error:
events.js:183
throw er; // Unhandled 'error' event
^
Error: connect ECONNREFUSED ******
at Object._errnoException (util.js:992:11)
at _exceptionWithHostPort (util.js:1014:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1186:14)
my request:
var https = require("https");
// Update these options with the details of the web service you would like to call
var options = {
method: 'GET',
uri: 'https:*****',
resolveWithFullResponse: true,
json: true
};
var req = https.request(options, res => {
res.setEncoding('utf8');
var returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ' + JSON.stringify(returnData))
var pop = JSON.parse(returnData).population;
callback(pop);
});
});
req.end();
javascript node.js get-request
javascript node.js get-request
edited yesterday
Yoram de Langen
3,90511727
3,90511727
asked 2 days ago
Germany DeutschlandGermany Deutschland
368
368
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
Here's an example, you can't set uri on the options object as such, you either use a uri string / URI object or you use the options object for this request type (see Node.js http.request docs)
const https = require('https');
const options = {
hostname: 'jsonplaceholder.typicode.com',
path: '/todos/1',
};
const req = https.request(options, (res) => {
let returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ', returnData);
});
});
req.on('error', (e) => {
console.error(e);
});
req.end();
add a comment |
There are two ways to define request options to be passed to https.request()
:
By specifying
hostname
,path
and (optionally)port
as separate request options:
var options = {
method: 'GET',
hostname: 'jsonplaceholder.typicode.com',
path: '/posts/1',
port: 443
};
By using creating an instance of url.URL:
var URL = require('url').URL;
var options = new URL('https://jsonplaceholder.typicode.com/posts/1');
For more information please refer to the official documentation.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54252784%2fget-reqeust-fails-with-error-connect-econnrefused%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
Here's an example, you can't set uri on the options object as such, you either use a uri string / URI object or you use the options object for this request type (see Node.js http.request docs)
const https = require('https');
const options = {
hostname: 'jsonplaceholder.typicode.com',
path: '/todos/1',
};
const req = https.request(options, (res) => {
let returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ', returnData);
});
});
req.on('error', (e) => {
console.error(e);
});
req.end();
add a comment |
Here's an example, you can't set uri on the options object as such, you either use a uri string / URI object or you use the options object for this request type (see Node.js http.request docs)
const https = require('https');
const options = {
hostname: 'jsonplaceholder.typicode.com',
path: '/todos/1',
};
const req = https.request(options, (res) => {
let returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ', returnData);
});
});
req.on('error', (e) => {
console.error(e);
});
req.end();
add a comment |
Here's an example, you can't set uri on the options object as such, you either use a uri string / URI object or you use the options object for this request type (see Node.js http.request docs)
const https = require('https');
const options = {
hostname: 'jsonplaceholder.typicode.com',
path: '/todos/1',
};
const req = https.request(options, (res) => {
let returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ', returnData);
});
});
req.on('error', (e) => {
console.error(e);
});
req.end();
Here's an example, you can't set uri on the options object as such, you either use a uri string / URI object or you use the options object for this request type (see Node.js http.request docs)
const https = require('https');
const options = {
hostname: 'jsonplaceholder.typicode.com',
path: '/todos/1',
};
const req = https.request(options, (res) => {
let returnData = "";
res.on('data', chunk => {
returnData = returnData + chunk;
});
res.on('end', () => {
console.log('returndata: ', returnData);
});
});
req.on('error', (e) => {
console.error(e);
});
req.end();
answered 2 days ago
Terry LennoxTerry Lennox
4,6752617
4,6752617
add a comment |
add a comment |
There are two ways to define request options to be passed to https.request()
:
By specifying
hostname
,path
and (optionally)port
as separate request options:
var options = {
method: 'GET',
hostname: 'jsonplaceholder.typicode.com',
path: '/posts/1',
port: 443
};
By using creating an instance of url.URL:
var URL = require('url').URL;
var options = new URL('https://jsonplaceholder.typicode.com/posts/1');
For more information please refer to the official documentation.
add a comment |
There are two ways to define request options to be passed to https.request()
:
By specifying
hostname
,path
and (optionally)port
as separate request options:
var options = {
method: 'GET',
hostname: 'jsonplaceholder.typicode.com',
path: '/posts/1',
port: 443
};
By using creating an instance of url.URL:
var URL = require('url').URL;
var options = new URL('https://jsonplaceholder.typicode.com/posts/1');
For more information please refer to the official documentation.
add a comment |
There are two ways to define request options to be passed to https.request()
:
By specifying
hostname
,path
and (optionally)port
as separate request options:
var options = {
method: 'GET',
hostname: 'jsonplaceholder.typicode.com',
path: '/posts/1',
port: 443
};
By using creating an instance of url.URL:
var URL = require('url').URL;
var options = new URL('https://jsonplaceholder.typicode.com/posts/1');
For more information please refer to the official documentation.
There are two ways to define request options to be passed to https.request()
:
By specifying
hostname
,path
and (optionally)port
as separate request options:
var options = {
method: 'GET',
hostname: 'jsonplaceholder.typicode.com',
path: '/posts/1',
port: 443
};
By using creating an instance of url.URL:
var URL = require('url').URL;
var options = new URL('https://jsonplaceholder.typicode.com/posts/1');
For more information please refer to the official documentation.
edited yesterday
answered 2 days ago
antonkuantonku
6796
6796
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54252784%2fget-reqeust-fails-with-error-connect-econnrefused%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown