Re: Internet download APIs only get first part of file, rest is blank

From: Randy Birch (rgb_removethis_at_mvps.org)
Date: 10/29/04


Date: Thu, 28 Oct 2004 22:28:46 -0400

Do you have to do it the hard way? There is a 1-line API that will download
a file from a ftp or http site to disk ... see
http://vbnet.mvps.org/code/internet/urldownloadtofilenocache.htm

-- 
Randy Birch
MS MVP Visual Basic
http://vbnet.mvps.org/
"Alan Silver" <alan-silver@nospam.thanx> wrote in message
news:XSGexSBbuPgBFwNp@nospamthankyou.spam...
: Hello,
:
: I'm having a problem with downloading a file from the internet. I am
: using the APIs shown in the code below.
:
: The problem is that I only seem to get the first part of the file. I
: have tried setting the buffer size to something way bigger than the size
: of page I am downloading, but the string returned only has the HTML for
: the first few hundred characters, then there's loads and loads of spaces
: filling up the rest of the string.
:
: Anyone any idea why? If you want to see the effect, call the following
: and look at the string returned ...
:
: sHTML =
: DownloadURL("http://FlowersAndGourmetGifts.com/links.php/A/1.html", "",
: 300000)
:
: Any ideas? TIA
:
: Alan
:
: Code for the download function follows ...
:
: Const INTERNET_OPEN_TYPE_DIRECT = 1
: Const INTERNET_OPEN_TYPE_PROXY = 3
: Const INTERNET_FLAG_RELOAD = &H80000000
: Private Declare Function InternetOpen Lib "wininet" Alias "InternetOpenA"
(ByVal sAgent As String, ByVal lAccessType As Long, ByVal sProxyName As
: String, ByVal sProxyBypass As String, ByVal lFlags As Long) As Long
: Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet As
Long) As Integer
: Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As
Long, ByVal sBuffer As String, ByVal lNumBytesToRead As Long,
: lNumberOfBytesRead As Long) As Integer
: Private Declare Function InternetOpenUrl Lib "wininet" Alias
"InternetOpenUrlA" (ByVal hInternetSession As Long, ByVal lpszUrl As String,
ByVal
: lpszHeaders As String, ByVal dwHeadersLength As Long, ByVal dwFlags As
Long, ByVal dwContext As Long) As Long
:
: Public Function DownloadURL(sURL As String, Optional sUserAgent As String
= "", Optional nSize As Long = 5000) As String
:      Dim hOpen As Long
:      Dim hFile As Long
:      Dim slBuffer As String
:      Dim Ret As Long
:      'Create a buffer for the file we're going to download
:      slBuffer = Space(nSize)
:      'Create an internet connection
:      hOpen = InternetOpen(sUserAgent, INTERNET_OPEN_TYPE_DIRECT,
vbNullString, vbNullString, 0)
:      'Open the url
:      hFile = InternetOpenUrl(hOpen, sURL, vbNullString, ByVal 0&,
INTERNET_FLAG_RELOAD, ByVal 0&)
:      'Read the file
:      InternetReadFile hFile, slBuffer, nSize, Ret
:      'clean up
:      InternetCloseHandle hFile
:      InternetCloseHandle hOpen
:      DownloadURL = slBuffer
: End Function
:
: -- 
: Alan Silver
: (anything added below this line is nothing to do with me)
:
:
: ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet
News==----
: http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000
Newsgroups
: ---= East/West-Coast Server Farms - Total Privacy via Encryption =---


Relevant Pages

  • Re: How to download a .txt file...?
    ... Public Sub CopyFileViaHTTP(rsURL As String, ... How can I download a .TXT file and don't lose the formatting? ... Private Declare Function InternetGetConnectedState Lib "wininet" (_ ...
    (microsoft.public.excel.programming)
  • Question for Randy Birch About Download File
    ... I am using the following code from Randy's site to download some extra files ... DownloadTempRegKey As String 'temporary download destination folder ... Private Declare Function RegQueryValueEx Lib "advapi32.dll" _ ... Dim dldata As FileRegistryDownloadData ...
    (microsoft.public.vb.general.discussion)
  • Re: parsing Html page
    ... will parse the string "mycode". ... Private Declare Function InternetOpen Lib "wininet" Alias ... Private Declare Function InternetCloseHandle Lib "wininet" (ByVal ...
    (microsoft.public.excel.programming)
  • Re: parsing Html page
    ... so I ask if there is the possibility to put in a string ... Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet ... Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As ... Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long ...
    (microsoft.public.excel.programming)
  • Re: parsing Html page
    ... so I ask if there is the possibility to put in a string ... Private Declare Function InternetCloseHandle Lib "wininet" (ByVal hInet ... Private Declare Function InternetReadFile Lib "wininet" (ByVal hFile As ... Dim hOpen As Long, hFile As Long, sBuffer As String, Ret As Long ...
    (microsoft.public.excel.programming)