【问题标题】:Set Proxy in VB.Net在 VB.Net 中设置代理
【发布时间】:2014-08-08 13:39:04
【问题描述】:

我正在运行以下代码来检查网站的排名代码。在我的国家禁止该网站之前,此代码运行良好。现在,如果我在我的电脑上使用代理或 VPN,它工作正常。那么如何在 PC 的默认代理设置上在该应用中设置手动代理(来自 TheBannedSite.com 和端口的代理)。

代码:

Try

    Dim str As String = New WebClient().DownloadString((url))

    Dim pattern = "When asked enter the code: <font color=blue>(\d{5,})\s<\/font>"
    Dim r = New Regex(pattern, RegexOptions.IgnoreCase)
    Dim m As Match = r.Match(str)

    If m.Success Then
        FlatLabel1.Text = "Code:: " + m.Groups(1).ToString()
        m = m.NextMatch()
        'Captcha1.Refresh()
    Else
        FlatLabel1.Text = "Please Check ur Network Connection First !!"
    End If

Catch
    Interaction.MsgBox("Please Check ur Network Connection First !! ", MsgBoxStyle.Information, "Error")
End Try

我尝试了以下代码:

Dim str As New System.Net.WebClient
str.Proxy = System.Net.HttpWebRequest.DefaultWebProxy
Dim Coder As String = str.DownloadString((url))

但它设置了我的电脑的 dafult 代理。 我要手动代理...

【问题讨论】:

    标签: vb.net proxy webclient


    【解决方案1】:

    您需要创建一个 WebProxy 对象,指定适当的属性并将其分配为 str.Proxy:

    Dim prox As New System.Net.WebProxy
    prox.Address = New Uri(...)
    prox.Credentials = New System.Net.NetworkCredential(...)
    
    str.Proxy = prox
    

    【讨论】:

      猜你喜欢
      • 2011-12-06
      • 2015-11-26
      • 2018-10-06
      • 2016-06-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多