🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #10574

Re: download file from internet

#10574
From: Remy Lebeau (TeamB)
Date: Mon, 05 Apr 2004 17:48
35 lines
2360 bytes
"ScOe" <cbinders@hotmail.com> wrote in message
news:406ab532@newsgroups.borland.com...

> hInternet = InternetOpen("CBZCommander", INTERNET_OPEN_TYPE_DIRECT,
>                NULL, NULL, INTERNET_FLAG_ASYNC);

The lpszAgent parameter is the same value that will be transmitted to the
HTTP server as the "user-agent" header.  You should format that string to
better match what browsers actually send.  Some HTTP servers are actually
designed to reject unknown/malformed user agents.

Also, why specify aschyronous mode if your code is not using the connection
asycnronously to begin with?

> i've use InternetOpen, InternetConnect, HttpOpenRequest,
> InternetReadFile but i allways get 0 sized file.

At no point in the code you have shown are you checking the WinInet
functions for errors.  Are any of them actually returning errors?

> HANDLE hFile = CreateFile("e:\\temp\\downloaded.tmp", GENERIC_WRITE,
>         FILE_SHARE_WRITE, NULL,CREATE_NEW, 0, 0);

Why would you share the file such that other processs could write to it at
the same time that you are?  You should use FILE_SHARE_READ instead.

>    while(InternetReadFile(hResource, &buf, sizeof(buf), &bytesRead)){

You should get rid of the '&' on the lpBuffer parameter:

    while(InternetReadFile(hResource, buf, sizeof(buf), &bytesRead)){


Gambit
Technical Details
Message-ID: <40719be3$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out1.nntp.be!propagator2-sterling!propagator3-cogent!news-in.nuthinbutnews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <406ab532@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,3762eecd161977b9
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2004-04-05 10:55:25 PST
From: "Remy Lebeau \(TeamB\)" <gambit47.no.spam@no.spam.yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <406ab532@newsgroups.borland.com>
Subject: Re: download file from internet
Date: Mon, 5 Apr 2004 10:48:24 -0700
Lines: 37
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
NNTP-Posting-Host: 67.22.138.253
Message-ID: <40719be3$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1081187299 67.22.138.253 (5 Apr 2004 10:48:19 -0800)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!news.glorb.com!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!news-out1.nntp.be!propagator2-sterling!propagator3-cogent!news-in.nuthinbutnews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail