zoukankan      html  css  js  c++  java
  • VB + API 获取 IE 的 "代理服务器" 配制

    Option Explicit
    Private Type INTERNET_PROXY_INFO
        dwAccessType    As Long
        lpszProxy       As Long
        lpszProxyBypass As Long
    End Type
    Private Const INTERNET_OPTION_PROXY = 38
    Private Declare Function InternetSetOption Lib "wininet.dll" Alias "InternetSetOptionA" (ByVal hInternet As Long, ByVal dwOption As Long, ByRef lpBuffer As Any, ByVal dwBufferLength As Long) As Long
    Private Declare Function InternetQueryOption Lib "wininet.dll" Alias "InternetQueryOptionA" (ByVal hInternet As Long, ByVal dwOption As Long, ByRef lpBuffer As Any, ByRef dwBufferLength As Long) As Long
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (ByRef pDest As Any, ByRef pSource As Any, ByVal Length As Long)
    Private Declare Function lstrcpy Lib "kernel32" Alias "lstrcpyA" (ByVal lpString1 As String, ByVal lpString2 As Long) As Long
    Private Declare Function lstrlen Lib "kernel32" Alias "lstrlenA" (ByVal lpString As Any) As Long
    Public Function GetProxyAddressAndPort(Optional ProxyType As String) As String
    Dim ProxyInfo As INTERNET_PROXY_INFO
    Dim arrBuffer() As Byte
    Dim strAddress As String
    Dim strBypass As String
    ReDim arrBuffer(0 To 4095)
    InternetQueryOption 0&, INTERNET_OPTION_PROXY, arrBuffer(0), UBound(arrBuffer) - LBound(arrBuffer) + 1
    CopyMemory ProxyInfo, arrBuffer(0), LenB(ProxyInfo)
    strAddress = VBA.Space(lstrlen(ProxyInfo.lpszProxy))
    lstrcpy ByVal strAddress, ProxyInfo.lpszProxy
    '不使用代理的地址 strBypass
    strBypass = VBA.Space(lstrlen(ProxyInfo.lpszProxyBypass))
    lstrcpy ByVal strBypass, ProxyInfo.lpszProxyBypass
    'GetProxyAddressAndPort = VBA.Trim(VBA.Replace(strAddress, " ", ";")) ' & ";" & VBA.Replace(strBypass, " ", ";"))
    GetProxyAddressAndPort = VBA.Trim(VBA.Replace(strAddress, " ", ";") & ";" & VBA.Replace(strBypass, " ", ";"))
    Dim ProxyArray() As String
    ProxyArray = Split(GetProxyAddressAndPort, ";")
    Dim i As Integer
    For i = LBound(ProxyArray) To UBound(ProxyArray)
        If ProxyArray(i) Like "*" & ProxyType & "=*" Then
           GetProxyAddressAndPort = VBA.Replace(ProxyArray(i), ProxyType & "=", "")
           Exit For
        End If
    Next i
    End Function

    Private Sub Command1_Click()
    MsgBox GetProxyAddressAndPort("http")
    MsgBox GetProxyAddressAndPort("ftp")
    MsgBox GetProxyAddressAndPort("gopher")
    End Sub

    '编程配置 IE 的 "代理服务器" 要用到 InternetSetOption
    '一个例子下载:
    'http://www.vbip.com/forum/files/webbrowser_proxy.zip

  • 相关阅读:
    SqlLite的使用
    asp.net批量上传图片带进度条显示
    对于GridView控件的RowDataBount事件的错误理解
    关于SQL中时间对比
    关于使用触发器时使用@@identity的问题
    关于Treeview控件如何给每个节点加js脚本的方法
    /etc/init.d/functions详解
    如何解决安装DreamWeaver8 时候提示“无法将数值写入键/SOFTWARE/classes/.shtml”
    [请教]关于超大数据量网站的数据搜索和分页的实现方法
    svchost.exe[900]中发生未处理的win32异常
  • 原文地址:https://www.cnblogs.com/Microshaoft/p/2485798.html
Copyright © 2011-2022 走看看