Click here to Skip to main content
15,616,520 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

I am working on a application which needs to detect internet and download some files from server. I am using http webrequest/response logic for internet detect logic. It is working fine but fails if tried on network which has proxy server in place.

I am on a corporate network and the request has to go through the proxy. To overcome this I used the below logic after searching in google.

HttpWebRequest webRequest =
(HttpWebRequest) (WebRequest.Create(""));
IWebProxy proxy = WebRequest.GetSystemWebProxy();
proxy.Credentials = CredentialCache.DefaultNetworkCredentials;
webRequest.Proxy = proxy;

HttpWebResponse webResponse =(HttpWebResponse) (webRequest.GetResponse());

With this it started working but has dependency on the following settings in IE->Connections->LAN Settings

1) Automatically detect settings
2) Use automatic configuration script

Both these options needs to be selected for the above logic to work. But I am able to browse internet if I have just the 2nd option (Use automatic configuration script) selected which points to a valid script. So, my expectaion is the logic should also work, if just this option is selected. But it gives the below exception

The remote name could not be resolved: ''

However, if both option 1 and 2 are selected in IE LAN settings, then the above logic works fine.

Please help me understand the reason for this behavior and how to solve.

Thanks in advance.

1 solution

Share this answer
HalliHaida 29-Mar-13 3:38am    
Hi Jose,

Thanks for the link. But that is not what I am looking for.

I would like to know why setting those two options in IE is working and just setting the Automatic script thing doesn't work. With just the automatic script thing set, I am able to access the internet using IE. So, the HttpWebRequest response should also work right?

But it is not. I am tryin to understand the reason for this behavior.

Please let me know if not clear.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900