Quantcast
Channel: Active questions tagged https - Stack Overflow
Viewing all articles
Browse latest Browse all 1547

How to handle large-size(8Mb) GET requests in Node.js

$
0
0

I'am trying to call this APIhttps://cwe-api.mitre.org/api/v1/cwe/weakness/allfrom node.js server, this suppose to get data of 8MB, However I get this error

Error: read ECONNRESETat TLSWrap.onStreamRead (node:internal/stream_base_commons:217:20) { errno: -4077, code: 'ECONNRESET', syscall: 'read' }

I have tried to make timeout 5 min and using Axios but nothing seems to work, However when I use postman to send this Requests it fetch the request in about 2.5 sec without any problem.

 const sendHttpRequest = async (method, url, timeout = null) => { const https = require('https');        return new Promise((resolve, reject) => {            const agent = new https.Agent({                keepAlive: true,                maxSockets: 100            });            const options = {                method: method,                timeout: timeout,                agent: agent            };            const req = https.request(url, options, (res) => {                let data = '';                // Handle incoming data                res.on('data', (chunk) => {                    data += chunk;                });                // Resolve the promise with the full data once the response ends                res.on('end', () => {                    resolve(data);                });            });            req.on('error', (error) => {                reject(error);            });            req.on('timeout', () => {                reject(new Error('Request timed out'));            });            req.end();        }); Using Service const cweThreatArrayDbURL = 'https://cwe-api.mitre.org/api/v1/cwe/weakness/all';let apiData = sendHttpRequest("GET", cweThreatArrayDbURL, (30*1000))    .then((data)=> console.log('response', data))    .catch(err => console.log(err));

Viewing all articles
Browse latest Browse all 1547

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>