您的位置:首页 > 编程语言 > VB

Visual Basic.Net 代理服务器的实例

2014-11-07 07:15 351 查看
' Create a new request to the mentioned URL.
Dim myWebRequest As HttpWebRequest = CType(WebRequest.Create(http://www.lob.cn), HttpWebRequest)

' Obtain the 'Proxy' of the  Default browser.
Dim proxy as IWebProxy = CType(myWebRequest.Proxy, IWebProxy)
' Print the Proxy Url to the console.
If Not proxy Is Nothing Then
Console.WriteLine("Proxy: {0}", proxy.GetProxy(myWebRequest.RequestUri))
Else
Console.WriteLine("Proxy is null; no proxy will be used")
End If

Dim myProxy As New WebProxy()

Console.WriteLine(ControlChars.Cr + "Please enter the new Proxy Address that is to be set ")
Console.WriteLine("(Example:http://www.ilu.com.cn:8080)")
Dim proxyAddress As String
Try
proxyAddress = Console.ReadLine()
If proxyAddress.Length = 0 Then
myWebRequest.Proxy = myProxy
Else
Console.WriteLine(ControlChars.Cr + "Please enter the Credentials (may not be needed)")
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)
Catch

End try
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: