Answer the question
In order to leave comments, you need to log in
What is the correct way to make an http request in a request in node.js?
Hi all!
Tell me please, am I doing the http request correctly?
In the first request, there are event ids, and in the second request, by event id, I already get detailed information and I need to output a number of information from the first and second requests to the console. Here is an example of my code
Request.get({
url: `https://example.com/?action=get_events&APIkey`,
json: true,
headers: {'User-Agent': 'request'}
}, (err, res, body) => {
if (err) {
console.log('Error:', err);
} else if (res.statusCode !== 200) {
console.log('Status:', res.statusCode);
} else {
if (body && body.length > 0) {
for (let event of body) {
let eventId = event.event_id
Request.get({
url: `https://example.com/?action=get_events&${eventId}&APIkey`,
json: true,
headers: {'User-Agent': 'request'}
}, (err, res, odds) => {
if (err) {
console.log('Error:', err);
} else if (res.statusCode !== 200) {
console.log('Status:', res.statusCode);
} else {
if (odds && odds.length > 0) {
console.log(event.event_name);
}
}
});
}
}
}
});
Error: { Error: read ECONNRESET
at _errnoException (util.js:1022:11)
at TLSWrap.onread (net.js:628:25) code: 'ECONNRESET', errno: 'ECONNRESET', syscall: 'read' }
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question