js前端如何判断请求是否有经过代理

javascript detect proxy:

how to detect a proxy using javascript

https://stackoverflow.com/questions/19767589/how-to-detect-a-proxy-using-javascript

var proxyHeader = 'via';
var req = new XMLHttpRequest();
req.open('GET', document.location, false);
req.send();
var header = req.getResponseHeader(proxyHeader);
if (header) {
    // we are on a proxy
}

or

$.ajax({
   type: 'POST',
   url:'http://www.google.com',
   data: formData,
   success: function(data, textStatus, request){
        if(request.getResponseHeader('X-Forwarded-For')) !== undefined)
            alert("Proxy detected !");
   }
  });

你可能感兴趣的:(js前端如何判断请求是否有经过代理)