HTTP Via A Proxy

Discussion in 'Visual Basic .NET' started by v7web, Feb 5, 2011.

  1. v7web

    v7web Registered Member

    Joined:
    Jul 15, 2010
    Messages:
    59
    Likes Received:
    3
    Hi,
    Can anyone give me some example code or links to help me with http post via a proxy.
    I have mastered the webbrowser control in vb.net and am now moving on to httpwebrequest.
    Many thanks.
     
  2. m3ownz

    m3ownz Regular Member

    Joined:
    Dec 12, 2009
    Messages:
    315
    Likes Received:
    136
    HTML:
        Dim request As HttpWebRequest = HttpWebRequest.Create("http://www.google.com")
           request.Proxy = New Net.WebProxy(ip:port)
           request.Timeout = 5000 'set timeout
           request.KeepAlive = False
    
    
           Dim response As HttpWebResponse = request.GetResponse()
           Dim sr As StreamReader = New StreamReader(response.GetResponseStream())
           Dim pageSourceCode As String = sr.ReadToEnd()
    
     
    • Thanks Thanks x 1
  3. v7web

    v7web Registered Member

    Joined:
    Jul 15, 2010
    Messages:
    59
    Likes Received:
    3
    Many thanks m3ownz
     
  4. blogbd1

    blogbd1 Power Member

    Joined:
    Apr 19, 2008
    Messages:
    568
    Likes Received:
    356
    Location:
    Undetected
    I use the following one, works fine for me.

    Code:
    request.Proxy = New WebProxy("218.100.22.60:80")
     
  5. jangedoo

    jangedoo Registered Member

    Joined:
    Jan 12, 2010
    Messages:
    59
    Likes Received:
    41
    thanks m3ownz, I was also looking for the same thing. I couldn't change the proxy for httpwebrequest before now it works!
     
  6. shudogg

    shudogg Regular Member

    Joined:
    Sep 23, 2008
    Messages:
    412
    Likes Received:
    153
    Occupation:
    Internet Marketing
    Location:
    Indiana
    If it is for an app that will be used by other people, look into supporting private proxies. You will need to give them the option to say "my proxies require username/password" by having a checkbox. They check the box, and it unlocks the Proxy Username and Proxy Password text boxes.

    In your webrequest code, add a check to get the checkstate of the checkbox. If it is checked, then pass the credentials in the WebRequest.
     
  7. Hydrogen

    Hydrogen Newbie

    Joined:
    Dec 30, 2009
    Messages:
    39
    Likes Received:
    23
    Occupation:
    Co-Owner of AdvertMarketing

    And to do that you extend out the previous proxy example like this.

    Code:
    Dim IP as string = "127.0.0.1"
    Dim PORT as string = "8080"
    Dim USERNAME as string = "TestUser"
    Dim PASSWORD as string = "TestPass"
    
    Dim proxy As New WebProxy(IP & ":" & PORT, True)
    proxy.Credentials = New NetworkCredential(USERNAME, PASSWORD)
    request.Proxy = proxy