使用URLDownloadToFile这个API下载一个文件。
但是却发现下载到的是存在于CATCH中的东西,我手动在IE中可以下载到最新的文件,而使用URLDownloadToFile却只能下载到一个旧的文件。不知道是怎么回事。我到底是应该在程序中再写点什么东西解决呢,还是需要设置我的操作系统呢?
顺便说一下我这里的情况:客户机通过PROXY SERVER上网的,我查看了PROXY服务器的设置,没有开启CATCH功能。因为需要下载的是一个LOG文件,随时都可能需要用到,并且数据也随时改变的。最好不要没头没脑贴一大段代码上来,偶看不懂别人的程序的,呵呵。说个原理就行,偶会自己琢磨的。顺便一说,可用分又过1000了,散散。

解决方案 »

  1.   

    又有没有可能它只是在我本地机的CATCH中找到了一个旧的文件,就算“下载”了呢?
    有没有遇到过同样情况的朋友阿?你们是如何解决的呢?
      

  2.   

    遇到,好像就是直接拿IE缓存里的东西,试试WinSock下载的方法吧,虽然麻烦,至少还能显示下载进度
      

  3.   

    接分哦,高手们都不用Inet ,webbrowser
      

  4.   

    但是却发现下载到的是存在于CATCH中的东西,我手动在IE中可以下载到最新的文件,而使用URLDownloadToFile却只能下载到一个旧的文件--------------------------
    清楚是什麼意思?
      

  5.   

    我用来再局域网中下载,好像没有遇到你说的问题。
    我下载的是exe文件。
      

  6.   

    找到一篇文章及代码,和楼主的问题相同。原文地址:
    http://vbnet.mvps.org/index.html?code/internet/urldownloadtofilenocache.htmOption Explicit
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Copyright ©1996-2005 VBnet, Randy Birch, All Rights Reserved.
    ' Some pages may also contain other copyrights by the author.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ' Distribution: You can freely use this code in your own
    '               applications, but you may not reproduce 
    '               or publish this code on any web site,
    '               online service, or distribute as source 
    '               on any media without express permission.
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Private 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 Declare Function DeleteUrlCacheEntry Lib "Wininet.dll" _
       Alias "DeleteUrlCacheEntryA" _
      (ByVal lpszUrlName As String) As Long
       
    Private Const ERROR_SUCCESS As Long = 0
    Private Const BINDF_GETNEWESTVERSION As Long = &H10
    Private Const INTERNET_FLAG_RELOAD As Long = &H80000000
    Private Sub Form_Load()   Command1.Caption = "Download File"
       Command2.Caption = "Clear Cache && Download"
       
    End Sub   
    Private Sub Command1_Click()   Dim sSourceUrl As String
       Dim sLocalFile As String
       Dim hfile As Long
       
       sSourceUrl = "http://vbnet.mvps.org/code/faq/fileloadtext.htm"
       sLocalFile = "c:\deleteme.htm"
       
       Label1.Caption = sSourceUrl
       Label2.Caption = sLocalFile
       
       If DownloadFile(sSourceUrl, sLocalFile) Then
       
          hfile = FreeFile
          Open sLocalFile For Input As #hfile
             Text1.Text = Input$(LOF(hfile), hfile)
          Close #hfile
          
       End IfEnd Sub
    Private Sub Command2_Click()   Dim sSourceUrl As String
       Dim sLocalFile As String
       Dim hfile As Long
       
       sSourceUrl = "http://vbnet.mvps.org/code/faq/fileloadtext.htm"
       sLocalFile = "c:\deleteme.htm"
       
       Label1.Caption = sSourceUrl
       Label2.Caption = sLocalFile
       
      'Attempt to delete any cached version of
      'the file. Since we're only interested in
      'nuking the file, the routine is called as
      'a sub. If the return value is requires
      '(calling as a function), DeleteUrlCacheEntry
      'returns 1 if successful, or 0 otherwise, e.g.
      '  If DeleteUrlCacheEntry(sourceUrl) = 1 Then
      '     Debug.Print "cached file found and deleted"
      '  Else
      '     Debug.Print "no cached file for " & sourceUrl
      '  End If
      'Note that the remote URL is passed as this is the
      'name the cached file is known by. This does NOT 
      'delete the file from the remote server.
       Call DeleteUrlCacheEntry(sSourceUrl)
       
       If DownloadFile(sSourceUrl, sLocalFile) = True Then         hfile = FreeFile
             Open sLocalFile For Input As #hfile
                Text1.Text = Input$(LOF(hfile), hfile)
             Close #hfile   End If
       
    End Sub
    Private Function DownloadFile(sSourceUrl As String, _
                                  sLocalFile As String) As Boolean
      
      'Download the file. BINDF_GETNEWESTVERSION forces 
      'the API to download from the specified source. 
      'Passing 0& as dwReserved causes the locally-cached 
      'copy to be downloaded, if available. If the API 
      'returns ERROR_SUCCESS (0), DownloadFile returns True.
       DownloadFile = URLDownloadToFile(0&, _
                                        sSourceUrl, _
                                        sLocalFile, _
                                        BINDF_GETNEWESTVERSION, _
                                        0&) = ERROR_SUCCESS
       
    End Function
      

  7.   

    好像没有什么好办法,这个代码你可以参考一下,它首先调用DeleteUrlCacheEntry将Cache中的项删除以后再执行URLDownloadToFile下载的:http://vbnet.mvps.org/index.html?code/internet/urldownloadtofilenocache.htm
      

  8.   

    这里还有一个解决方法:
    http://www.autohotkey.com/docs/commands/URLDownloadToFile.htm大致的意思就是传递一个假的参数来强制下载,例如:http://.../test.exe?fakeParam=42