Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c# HttpWebRequest doesnt reflect vpn location change

First Code,

HttpWebRequest req = (HttpWebRequest)WebRequest.Create(formUrl);
 req.Method = "GET";
 req.KeepAlive = true ;
 req.Proxy = WebRequest.GetSystemWebProxy();

Simple HttpWebRequest call to a site. Problem lies within Network detection. As this module work on a site for some time, sometimes need to change ip address and I acquire this by vpn. But VPN location change effect is not obvious, subsequent calls can't detect network change. It takes a long time for detection.But if I close the software and open again, it works with current vpn location from the start. That means in flight it cannot detect changes quickly, but it can detect if it restarted. Does ServicePointManager or other settings can achieve this without restarting the program?

like image 495
Ayan_84 Avatar asked Dec 07 '25 04:12

Ayan_84


1 Answers

Had the same issue. In case anyone else stumbles into this question, the solution for me was to use System.Net.Http's HttpClient instead of WebRequest

like image 115
SILENT Avatar answered Dec 08 '25 18:12

SILENT