【问题标题】:How to change the proxy of the WebBrowser?如何更改 WebBrowser 的代理?
【发布时间】:2012-08-14 14:19:16
【问题描述】:

我所说的 webbrowser 是指在 VB 中创建的对象,而不是 chrome 或 IE。如何更改浏览器用于浏览页面的代理?

【问题讨论】:

    标签: .net vb.net proxy


    【解决方案1】:

    我在互联网上用 C# 找到了你的问题的解决方案,所以这是我可以推荐的 VB 版本。只需确保导入 System.Runtime.InteropServices。

    <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 RefreshIESettings(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
    
                            ' Filling in structure
                            struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
                            struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
                            struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")
    
                            ' Allocating memory
                            Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))
    
                            ' Converting structure to IntPtr
                            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
    

    【讨论】:

      【解决方案2】:
      猜你喜欢
      • 2010-10-30
      • 2012-03-17
      • 1970-01-01
      • 2011-05-30
      • 1970-01-01
      • 1970-01-01
      • 2021-10-11
      相关资源
      最近更新 更多