谁有VB HTTP下载 教程啊!

解决方案 »

  1.   

    'Example Name:Downloading Files using URLDownloadToFile  '------------------------------------------------------------------------------
    '
    ' Form Code
    '
    '------------------------------------------------------------------------------
    Option ExplicitPrivate Declare Function URLDownloadToFile Lib "urlmon" _
       Alias "URLDownloadToFileA" _
      (ByVal pCaller As Long, _
       ByVal szURL As String, _
       ByVal szFileName As String, _
       ByVal dwReserved As Long, _
       ByVal lpfnCB As Long) As Long
       
    Private Const ERROR_SUCCESS As Long = 0
       
    Private Sub Form_Load()   Command1.Caption = "Download File"
       
    End Sub   
    Private Sub Command1_Click()   Dim sourceUrl As String
       Dim targetFile As String
       Dim hfile As Long
       
       sourceUrl = "http://www.mvps.org/vbnet/faq/main/fileloadtext.htm"
       targetFile = "c:\deleteme.htm"
       
       Label1.Caption = sourceUrl
       Label2.Caption = targetFile
       
       If DownloadFile(sourceUrl, targetFile) Then
       
          hfile = FreeFile
          Open targetFile For Input As #hfile
             Text1.Text = Input$(LOF(hfile), hfile)
          Close #hfile
          
       End IfEnd Sub
    Public Function DownloadFile(ByVal sURL As String, _
                                 ByVal sLocalFile As String) As Boolean   Dim lngRetVal As Long
       
      'if the API returns ERROR_SUCCESS (0), 
      'return True from the function 
       DownloadFile = URLDownloadToFile(0&, _
                                        sURL, _
                                        sLocalFile, _
                                        0&, _
                                        0&) = ERROR_SUCCESS
       
    End Function
      

  2.   

    Option ExplicitPrivate Declare Function URLDownloadToFile Lib "urlmon" _
       Alias "URLDownloadToFileA" _
      (ByVal pCaller As Long, _
       ByVal szURL As String, _
       ByVal szFileName As String, _
       ByVal dwReserved As Long, _
       ByVal lpfnCB As Long) As Long
       
    Private Const ERROR_SUCCESS As Long = 0
       
    Private Sub Form_Load()   Command1.Caption = "Download File"
       
    End Sub   
    Private Sub Command1_Click()   Dim sourceUrl As String
       Dim targetFile As String
       Dim hfile As Long
       
       sourceUrl = "http://192.168.0.4/dd/1.bmp"
       targetFile = "d:\123\1.bmp"
       
       Label1.Caption = sourceUrl
       Label2.Caption = targetFile
       
       If DownloadFile(sourceUrl, targetFile) Then
       
          hfile = FreeFile
          Open targetFile For Input As #hfile
             Text1.Text = Input$(LOF(hfile), hfile)
          Close #hfile
          
       End IfEnd Sub
    Public Function DownloadFile(ByVal sURL As String, _
                                 ByVal sLocalFile As String) As Boolean   Dim lngRetVal As Long
       
      'if the API returns ERROR_SUCCESS (0),
      'return True from the function
       DownloadFile = URLDownloadToFile(0&, _
                                        sURL, _
                                        sLocalFile, _
                                        0&, _
                                        0&) = ERROR_SUCCESS
       
    End Function
    这样写怎么还是不行啊?