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

            ' 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值