Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB.net代理异常_Vb.net_Proxy_Webbrowser Control - Fatal编程技术网

VB.net代理异常

VB.net代理异常,vb.net,proxy,webbrowser-control,Vb.net,Proxy,Webbrowser Control,我使用代理的代码可以工作,但当代理无效或受限时,我的程序直接使用我的IP地址,我使用的web浏览器直接检查我的IP,是否有任何方法可以在我使用的代理无效或受限时设置异常 这是我的工作代码: Imports System.Runtime.InteropServices #Region "Using Proxy" <Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _

我使用代理的代码可以工作,但当代理无效或受限时,我的程序直接使用我的IP地址,我使用的web浏览器直接检查我的IP,是否有任何方法可以在我使用的代理无效或受限时设置异常

这是我的工作代码:

Imports System.Runtime.InteropServices 
   #Region "Using Proxy"
        <Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _
        Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
        End Function

        Public Structure Struct_INTERNET_PROXY_INFO
            Public dwAccessType As Integer
            Public proxy As IntPtr
            Public proxyBypass As IntPtr
        End Structure

        Private Sub UseProxy(ByVal strProxy As String)
            Const INTERNET_OPTION_PROXY As Integer = 38
            Const INTERNET_OPEN_TYPE_PROXY As Integer = 3

            Dim struct_IPI As Struct_INTERNET_PROXY_INFO

            struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
            struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
            struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")

            Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))

            Marshal.StructureToPtr(struct_IPI, intptrStruct, True)

            Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
        End Sub
    #End Region

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    UseProxy(ProxyText.Text)
    WebBrowser1.Navigate("ipchicken.com")

    End Sub
导入System.Runtime.InteropServices
#区域“使用代理”
_
私有共享函数InternetSetOption(ByVal hInternet作为IntPtr,ByVal dwOption作为Integer,ByVal lpBuffer作为IntPtr,ByVal lpdwBufferLength作为Integer)作为布尔值
端函数
公共结构结构结构互联网代理信息
作为整数的公共dwAccessType
作为IntPtr的公共代理
作为IntPtr的公共代理旁路
端部结构
专用子UseProxy(ByVal strProxy作为字符串)
常量INTERNET\u选项\u代理为整数=38
Const INTERNET\u OPEN\u TYPE\u代理为整数=3
Dim结构IPI作为结构INTERNET代理信息
struct_IPI.dwAccessType=INTERNET_OPEN_TYPE_PROXY
struct_IPI.proxy=Marshal.StringToHGlobalAnsi(strProxy)
struct_IPI.proxyBypass=Marshal.StringToHGlobalAnsi(“本地”)
Dim INTPTRSSTRUCT As IntPtr=Marshal.allocTaskMem(Marshal.SizeOf(struct_IPI))
Marshal.StructureToPtr(struct_IPI,intptrStruct,True)
Dim iReturn As Boolean=InternetSetOption(IntPtr.Zero、INTERNET\u OPTION\u PROXY、intptrStruct、System.Runtime.InteropServices.Marshal.SizeOf(struct\u IPI))
端接头
#末端区域
私有子按钮1\u单击(发送者作为对象,e作为事件参数)处理按钮1。单击
UseProxy(ProxyText.Text)
WebBrowser1.Navigate(“ipchicken.com”)
端接头

尝试以下解决方案:

我相信,如果您将地址绑定到该特定ip,它将不起作用,如果该ip无效或不起作用,并且不会使用您的系统默认值。

在try-catch块中为失败的行包装代码?