Testing reachability of WebRequest.Proxy for work / home app

T

Tim Regan

Hi All,

I'm writing an app using WebRequest in csharp. I need the app to respond to
the host PC moving from one network to another, e.g. taking a laptop home
after work. Currently the WebRequest.Proxy is always picked up from the work
network settings, so that the GetResponse method throws a WebException when
the proxy is unreachable. But IE works fine across the two networks.

I've two questions.

1) Where is WebRequest getting the default proxy information from? I'd
assumed that it picked it up from IE's settings, but that doesn't explain
why IE makes the transition from work to home without problem while
WebRequest fails.

2) How do I test the reachability of the WebRequest.Proxy before calling
GetResponse? If I could test it first I could replace it with
GlobalProxySelection.GetEmptyWebProxy for the home network.

Cheers,

Tim.
 
J

Joerg Jooss

Tim said:
Hi All,

I'm writing an app using WebRequest in csharp. I need the app to
respond to the host PC moving from one network to another, e.g.
taking a laptop home after work. Currently the WebRequest.Proxy is
always picked up from the work network settings, so that the
GetResponse method throws a WebException when the proxy is
unreachable. But IE works fine across the two networks.

I've two questions.

1) Where is WebRequest getting the default proxy information from?
I'd assumed that it picked it up from IE's settings, but that doesn't
explain why IE makes the transition from work to home without problem
while WebRequest fails.

Read this thread (it's somewhat messy):

http://tinyurl.com/48q9o
2) How do I test the reachability of the WebRequest.Proxy before
calling GetResponse? If I could test it first I could replace it with
GlobalProxySelection.GetEmptyWebProxy for the home network.

Unless the proxy's IP address is entered in your hosts file or you're
accessing it by IP address, the DNS lookup will already fail. So you
can try Dns.Resolve(), or if no DNS is involved, try to connect to the
proxy's HTTP port using (using Sockets, WebRequest, WebClient, ...).

Cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top