我新架設的網站「呼浩網」歡迎大家來看看喔

當然這個blog還是會繼續經營

先紀錄一下,也許這個方法可以拿來衝人氣!

設定HttpWebRequest Proxy

下列程式碼範例會使用 Proxy 方法,取得要求的 Proxy 資訊。

 

' Create a new request to the mentioned URL.                
Dim myWebRequest As HttpWebRequest = CType(WebRequest.Create("http://www.microsoft.com"), HttpWebRequest)
Dim myProxy As New WebProxy()
' Obtain the 'Proxy' of the  Default browser.  
myProxy = CType(myWebRequest.Proxy, WebProxy)
' Print the Proxy Url to the console.
Console.WriteLine(ControlChars.Cr + "The actual default Proxy settings are {0}", myProxy.Address)
Try
    Console.WriteLine(ControlChars.Cr + "Please enter the new Proxy Address that is to be set ")
    Console.WriteLine("(Example:http://myproxy.example.com:port)")
    Dim proxyAddress As String
    proxyAddress = Console.ReadLine()
    If proxyAddress.Length = 0 Then
        myWebRequest.Proxy = myProxy
    Else
        Console.WriteLine(ControlChars.Cr + "Please enter the Credentials")
        Console.WriteLine("Username:")
        Dim username As String
        username = Console.ReadLine()
        Console.WriteLine(ControlChars.Cr + "Password:")
        Dim password As String
        password = Console.ReadLine()
        ' Create a new Uri object.
        Dim newUri As New Uri(proxyAddress)
        ' Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
        myProxy.Address = newUri
        ' Create a NetworkCredential object and associate it with the Proxy property of request object.
        myProxy.Credentials = New NetworkCredential(username, password)
        myWebRequest.Proxy = myProxy
    End If
    Console.WriteLine(ControlChars.Cr + "The Address of the  new Proxy settings are {0}", myProxy.Address)
    Dim myWebResponse As HttpWebResponse = CType(myWebRequest.GetResponse(), HttpWebResponse)
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 kingjoy1235 的頭像
    kingjoy1235

    King的幸福國度

    kingjoy1235 發表在 痞客邦 留言(0) 人氣()