WebProxy with System.Net.WebClient

Discussion in 'ASP .Net Security' started by Shahid, Sep 24, 2005.

  1. Shahid

    Shahid Guest

    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
     
    Shahid, Sep 24, 2005
    #1
    1. Advertising

  2. Shahid

    Joerg Jooss Guest

    Shahid wrote:

    > 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,
    --
    http://www.joergjooss.de
    mailto:
     
    Joerg Jooss, Sep 24, 2005
    #2
    1. Advertising

  3. Shahid

    Joerg Jooss Guest

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

    Cheers,
    --
    http://www.joergjooss.de
    mailto:
     
    Joerg Jooss, Sep 24, 2005
    #3
  4. Shahid

    Shahid Guest

    Hey,

    That's CoOoOl.
    it works.

    Thank You man.


    "Joerg Jooss" wrote:

    > Out of curiosity, I just tried my proposed GlobalProxySelection.Select
    > workaround, and it works :)
    >
    > Cheers,
    > --
    > http://www.joergjooss.de
    > mailto:
    >
     
    Shahid, Sep 25, 2005
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jon

    Timeout on system net webclient

    Jon, Feb 7, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    9,426
  2. Davide Bedin

    Impersonation and webproxy credentials

    Davide Bedin, Mar 3, 2004, in forum: ASP .Net Security
    Replies:
    3
    Views:
    268
    Alek Davis
    Mar 4, 2004
  3. Davide Bedin

    Impersonation and webproxy credentials

    Davide Bedin, Mar 3, 2004, in forum: ASP .Net Security
    Replies:
    0
    Views:
    133
    Davide Bedin
    Mar 3, 2004
  4. Shahid

    webProxy with webClient

    Shahid, Sep 24, 2005, in forum: ASP .Net Security
    Replies:
    0
    Views:
    137
    Shahid
    Sep 24, 2005
  5. Mike Bridge

    WebProxy ignored calling WebMethod

    Mike Bridge, May 1, 2006, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    195
    Mike Bridge
    May 1, 2006
Loading...

Share This Page