编程知识 cdmana.com

Using Axios to realize the never break connection of campus network

There is a mechanism for campus network service , If the server detects that you are not using the network for a period of time , Then the server will automatically disconnect your network , At first, I didn't care about anything , But recently I have a need for remote connection , It's better to be disconnected like this . So I used axios Wrote a piece of code , Not for a while to the server get request , Send twice , Each time interval is different . I tested it myself , It hasn't been detected by the server for more than 20 hours .

var i = 0
var j=0
var t =0
var min =0
var sucessHour = 0
var sucessMin =0
var errorTime =0
const axios = require('axios')
axios.default.withCredentials = true

setInterval(() => {
    axios.get('https://identity.getpostman.com/accounts?continue=https%3A%2F%2Fweb.postman.co%2Fbuild%2Fworkspace%2FMy-Workspace~76fb544d-c200-40ff-8361-2b39a5ad162a1',{withCredentials:true}
	
,{
    // params:{
    //     "gnmkdm":"N305005","layout":"default","su":"19250112",
    // },
    
}
)
.then(function (response) {
    // handle success
    i=i+1
	sucessHour = Math.floor(i/60)
	sucessMin = i%60
    console.log(' No drop service is running '+sucessHour+' Hours '+sucessMin+' minute    '+Date().substring(15,30));
  })
  .catch(function (error) {
    // handle error
	
	i=0
	j=j+1
	t=Math.floor(j/60)
	min = j%60
    console.log(' It's off the net '+(t)+' Hours '+min+' minute , Need to reconnect ');
	//return Promise.reject(error)
  })
  .then(function () {
    // always executed
  });
}, 60000);

setInterval(()=>{
	axios.get('http://www.njmu.edu.cn').then(
	()=>{
	}
	)
},11000)

 Insert picture description here

版权声明
本文为[osc_ vrlg1skx]所创,转载请带上原文链接,感谢
https://cdmana.com/2020/12/20201224102147103H.html

Scroll to Top