Quantcast
Channel: Visual Studio General Questions forum
Viewing all articles
Browse latest Browse all 21115

Httpwebrequest not respecting hosts file

$
0
0

Httpwebrequest not respecting hosts file

17 hours, 14 minutes ago|LINK

I'm using the .NET WebRequest while changing my HOSTS file. I'm observing that System.Net doesn't honor those changes - how can I make it do so?

I have a number of servers load-balanced behind a single hostname, let's say 'example.com'. I want to target several of them individually, so my program will hard-code the machine-specific IP address in my HOSTS file before sending a request to example.com:

163.56.0.34 example.com

For the first server and first request, this works fine. Then my program changes the HOSTS file again:

 163.56.0.48 example.com 

And I create a new HttpWebRequest. When I send this one off, I can observe in Fiddler that it goes to the first IP address (163.56.0.34) instead of the expected second one.

Tried

ServicePointManager.DnsRefreshTimeout=0; request.KeepAlive=false;

No use, If I make the program wait for 90 secs, its working then. After editing the host file and befire making a request, wait for 90 secs

System.Threading.Thread.Sleep(90000);--> working 

But it is the most stupid way to make my application work. Please shed some light. Thanks


Viewing all articles
Browse latest Browse all 21115

Trending Articles



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