WebProxy with System.Net.WebClient

S

Shahid

hi,

i m trying to get html from a website using asp.net. i wrote following code
to access html of a website. it works fine but whenever i try this code from
network (behind proxy server) , it gives me error " The underlying connection
was closed: Unable to connect to the remote server". i don't know how to
implement proxy class with in WebClient Class.

any kind of help would be greatly appricated :)


Dim objWC As New System.Net.WebClient
Return New System.Text.UTF8Encoding().GetString( _
objWC.DownloadData("http://www.myweb.com"))

Regards

Shahid
 
J

Joerg Jooss

Shahid said:
hi,

i m trying to get html from a website using asp.net. i wrote
following code to access html of a website. it works fine but
whenever i try this code from network (behind proxy server) , it
gives me error " The underlying connection was closed: Unable to
connect to the remote server". i don't know how to implement proxy
class with in WebClient Class.

Prior to .NET 2.0, WebClient does not expose a Proxy property like
HttpWebRequest does.

There's one work-around you might want to try: Before creating your
WebClient, create a WebProxy instance for your specific proxy server
and set it as default by calling GlobalProxySelection.Select =
yourProxy;

If that doesn't work, you have to use HttpWebRequest instead.

Cheers,
 
J

Joerg Jooss

Out of curiosity, I just tried my proposed GlobalProxySelection.Select
workaround, and it works :)

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

Members online

Forum statistics

Threads
473,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top