如何在vb6中使用inet中的代理?

时间:2011-05-13 19:44:22

标签: vb6

我正在vb6中制作一个程序。 我想在vb6中通过inet使用代理进行连接。怎么样呢?请帮忙。

谢谢

1 个答案:

答案 0 :(得分:3)

这是一个或多或少的通用功能,用于打开可以接受代理参数的互联网连接。这是如何使用代理的一个很好的例子。

Private Declare Function InternetOpen Lib "WinInet" Alias "InternetOpenA" (ByVal lpszAgent As String, ByVal lpAccessType As Long, ByVal lpszProxyName As String, ByVal lpszProxyBypass As String, ByVal lpFlags As Long) As Long

Public Function OpenInternet(ByVal sAppName As String, ByVal lAccessType As Long,  ByVal sProxyName As String, _
   ByVal sProxyBypass As String, ByVal lFlags As Long) As Boolean
   Dim Rtn As Long
   Dim lngINetHandle As Long
   Dim strHeaders As String
   Dim lngDllErr As Long

   On Error GoTo errOpenInternet

   RaiseEvent Operation("Opening internet connection")
   Rtn = InternetOpen(ByVal sAppName, ByVal lAccessType, ByVal sProxyName, ByVal sProxyBypass, ByVal lFlags)

   If Rtn = 0 Then   'failed for some reason
      lngDllErr = Err.LastDllError
      If lngDllErr <> 0 Then
         RaiseEvent Operation("Error " & CStr(lngDllErr))
         Err.Raise lngDllErr, "OpenInternet", ErrorOut(Err.LastDllError, "OpenInternet")
      End If
   Else
      RaiseEvent Operation("Connection opened")
      InternetHandle = Rtn
      ExtendedError = ""
   End If

   OpenInternet = CBool(Rtn)

   Exit Function

errOpenInternet:
   Err.Raise Err.Number, Err.Source & ":OpenInternet", Err.Description

End Function