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
相关文章推荐
- 官方水晶报表 .NET 应用程序实例下载 (Visual Basic .NET)
- 官方水晶报表 .NET 应用程序实例下载 (Visual Basic .NET)
- Visual Basic .NET资源工具包
- 从过去到未来、 从Visual和Basic到Net。(从VB到VB.NET的12个技巧)(二)
- 在 Visual Basic .NET 或 JScript 代码中使用早期绑定
- 与Visual Basic .NET一起使用.NET Framework
- Top 10 Reasons to Upgrade to Visual Basic .NET
- 阻止 Visual Basic .NET 或 C# 代码的反向工程
- 从过去到未来、 从Visual和Basic到Net。(从VB到VB.NET的12个技巧)
- 从 Visual Basic 6.0 到 Visual Basic.NET 的转换
- HOW TO: Transfer Data to an Excel Workbook by Using Visual Basic .NET
- Working with Multiple Forms in Visual Basic .NET: Upgrading to .NET
- 将Visual Basic 6.0程序转换到Visual Basic.NET
- .net入门之VB篇:Visual Basic.Net中的文件操作(一)
- 为更新到Visual Basic.NET准备你的Visual Basic 6.0应用程序
- Visual Basic.NET探密
- 效率提高两倍!——Visual Basic.net 新力量
- Visual Basic .NET Power Pack试用手记
- Visual Basic.Net 如何操作内存?
- Visual Basic.NET和GDI+共创图标编辑器