Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const https = require('https');
- const Agent = require('agentkeepalive').HttpsAgent;
- const keepaliveAgent = new Agent({
- maxSockets: 100,
- maxFreeSockets: 10,
- freeSocketTimeout: 30000, // free socket keepalive for 30 seconds
- });
- const options = {
- host: 'server',
- port: port,
- auth: 'username:password',
- path: '/path',
- method: 'POST',
- agent: keepaliveAgent,
- headers: {
- 'Accept': 'application/json'
- }
- };
- makeRequest();
- function makeRequest(){
- const req = https.request(options, res => {
- console.log('STATUS: ' + res.statusCode);
- console.log('HEADERS: ' + JSON.stringify(res.headers));
- res.setEncoding('utf8');
- res.on('data', function (chunk) {
- console.log('BODY: ' + chunk);
- });
- });
- req.on('error', e => {
- console.log('problem with request: ' + e.message);
- makeRequest();
- });
- req.end();
- }
- setInterval(() => {
- if (keepaliveAgent.statusChanged) {
- if(keepaliveAgent.getCurrentStatus().resetStatus != 0){
- keepaliveAgent.setCurrentStatus();
- makeRequest();
- }
- }
- }, 2000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement