Article View: borland.public.cppbuilder.internet.web
Article #448downloading with wininet
From: Boba
Date: Tue, 02 Jan 2007 06:21
Date: Tue, 02 Jan 2007 06:21
44 lines
2489 bytes
2489 bytes
Happy New Year!
I'm trying to figure out what's wrong with the following code.
Please help. Thanks.
void DownloadFile( LPCSTR szServerName, LPCSTR szFileName ){
HINTERNET hHttpNet, hHttpSession, hHttpRequest;
DWORD dwDataSize, dwBytesDownloaded;
LPCSTR szAcceptTypes[] = { "*.*", NULL };
BYTE Buffer[1024];
hHttpNet = InternetOpen( "Microsoft Internet Explorer",
INTERNET_OPEN_TYPE_PRECONFIG,
NULL, NULL, 0 );
if( hHttpNet ){
hHttpSession = InternetConnect( hHttpNet, szServerName,
INTERNET_DEFAULT_HTTP_PORT,
"anonymous", "",
INTERNET_SERVICE_HTTP, 0, 0 );
if( hHttpSession ){
hHttpRequest = HttpOpenRequest( hHttpSession, "GET", szFileName,
"HTTP/1.1", NULL, szAcceptTypes,
INTERNET_FLAG_RELOAD, 0 );
if( hHttpRequest ){
if( HttpSendRequest( hHttpRequest, NULL, 0, NULL, 0 ) ){
do{
if( InternetQueryDataAvailable( hHttpRequest, &dwDataSize, 0, 0 ) ){
if( InternetReadFile( hHttpRequest, (LPVOID)Buffer,
sizeof(Buffer),
&dwBytesDownloaded ) ){
/*write the data*/
}//if( InternetReadFile
}//if( InternetQueryDataAvailable(
} while( dwBytesDownloaded );
}//if( HttpSendRequest
InternetCloseHandle( hHttpRequest );
}//if( hHttpRequest )
InternetCloseHandle( hHttpSession );
}//if( hHttpSession )
InternetCloseHandle( hHttpNet );
}//if( hHttpNet )
}//DownloadFile
Technical Details
Message-ID:
<4599f9c5@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Thread: feeec,66a46201c905b896,start X-Google-Attributes: gidfeeec,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Boba" <Boba@somewhere.world> Newsgroups: borland.public.cppbuilder.internet.web Subject: downloading with wininet Date: Tue, 2 Jan 2007 00:21:40 -0600 Lines: 46 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1106 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 NNTP-Posting-Host: 65.243.37.30 Message-ID: <4599f9c5@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1167718853 65.243.37.30 (1 Jan 2007 22:20:53 -0800) Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail