请问如何在DELPHI中下载HTTPS或HTTP网页上的文件?(200分)

  • 主题发起人 主题发起人 once
  • 开始时间 开始时间
O

once

Unregistered / Unconfirmed
GUEST, unregistred user!
已知在某个WEB站点有一个文件,其url如下所示:
http://www.163.com/test/a.dat

https://www.163.com/test/a.dat。
请问我如何在DELPHI中下载该文件?(因为源文件地址和目的文件名均固定,所以不希望
出现保存文件的对话框)
 
THTTPGet 是利用 Microsoft Internet Explorer 内建的 WinInet.dll
透过 HTTP 通讯协议下载文件的非可视构件 ( 1.94 版,附源码 ),
作者 : UtilMind Solutions。

http://vcl.vclxx.org/DELPHI/D32FREE/HTTPGET.ZIP
 
谢谢hujunyi!
现在我已经按您给出的地址找到了这个控件且解决了我的问题。
但是HTTPS的问题仍然没有解决。
 
先给分再说啦。其实您可以在http://vcl.vclxx.org/这里找下,我记得是有的。
 
关注,我要源码!!!
 
直接用 nmftp or nmhttp
 
用Wininet函数,一个例子
unit Updater;
//{$A+,B-,D-,L-,M-,O+,Q-,R-,S-,X+,Y-}
(*
TChkUpdate 1.3

"Lets go get the net!"

-------- -------- -------- -------- -------- -------- -------- --------

Contents:
TChkUpdate - Component for checking wether an update of an application
is available on your homepage.

-------- -------- -------- -------- -------- -------- -------- --------
Copyrights (C) 1999 ved T Skovmand Eriksen
email: TSEriksen@cyberdude.com
ALL RIGHTS RESERVED
-------- -------- -------- -------- -------- -------- -------- --------

This source is freeware and may be used as follows:

* In development of in-house applications which will not be published.

* In development of freeware applications PROVIDED that credit is given
to me in the applications aboutbox or helpfile.

* In development of shareware and commercial applications PROVIDED that
I, Troels S Eriksen, recieve a free unlimited copy of all versions of
said application AND that credits are given to me in the applications
aboutbox or helpfile.

* In printed or electronic form (fx. in a book) or in a source-library
(fx. on CD) PROVIDED that I, Troels S Eriksen, recieve a royality-free
unlimited copy of said book or library.

* In any other way PROVIDED that I, Troels S Eriksen, give my explicit
permission to the suggested use.

By using this source you do acknowledge that the above restrictions apply to
you and your use of this component and that you will confirm by them.

-------- -------- -------- -------- -------- -------- -------- --------

Revision history:
TChkUpdate
01 - Component created.
02 - Ver. 1.1: Property for Version number check added.
03 - Internet Connection check added - doesn't seem to work, though...
04 - Ver. 1.2: AutoProxy property added thanks to Jura Kornienko.
05 - Minor bugfixes. Allows more loose syntax in ver/rev comments.
06 - Ver. 1.3: Background execute (Threaded) added.
07 - Threaded property added.

-------- -------- -------- -------- -------- -------- -------- --------

TChkUpdate Properties:
AutoProxy When TRUE uses IE's default proxy settings.
Homepage The URL to the main homepage of your company or
application. (Used by the OnFound method)
Revision Current revision. Is checked against the <!--rev #-->
comment on the webpage
Threaded When TRUE connects to the internet in a separate
thread for version/revision checking. When FALSE the
main thread is blocked while check occurs.
URL URL to an internet document containing the revision
comment to check for
Version Current version. Is checked against the <!--ver #.#-->
comment on the webpage

TChkUpdate Events
OnFound Triggered if the revision comment is greather than
the current revision. Use the Launch value to decide
wether the end-users default browser should open the
homepage.
OnNotFound Triggered if the above is not the true.
OnNoConnect Triggered if connection to the internet could not be
established or if the URL was not found.
TChkUpdate Methods:
Execute Connects to the url and checks the revision and version.
If Threaded is TRUE return value is always TRUE. If
Threaded is FALSE will only return TRUE if connection
to the server could be established and the URL found.
IsConnected Returns TRUE is an connection to the server defined
in the URL property may be established. FALSE will be
returned if no internet connection currently exists.

-------- -------- -------- -------- -------- -------- -------- --------

Requirements:
wininet.dll Windows 32bit Internet API library must be present
and working.

-------- -------- -------- -------- -------- -------- -------- --------

Thanks to:
Jura Kornienko Who had the ideas for rev. 04-06, made me sit up, add
a few lines of code and end up with a better component.

-------- -------- -------- -------- -------- -------- -------- --------

Bugs:
None reported - none fixed.

"It is not a bug, its an undisclosed feature for further extension of
this applications feasibility"

-------- -------- -------- -------- -------- -------- -------- --------

How to use:
First, create an webpage for your application. Somewhere within the
first kilobyte of this homepage, add a revision comment - like this:
"<!--rev #-->" and/or a version comment like this: "<!--ver #.##-->".
Everytime you update your app, increase the rev number (the #) or the
version number (the #.##) on this webpage.

Second, Drop a TChkUpdate component on your main form, enter the URL to
the webpage in the URL property and the current revision number in the
Revision property and the current version number in the version property.

Add some code to the OnFound / OnNotFound properties to inform the
end-user wether there is an update available or not. If you set the
variable Launch to true, the users browser will automatically show
the URL from the Homepage property. (Would be nice to ask the users
permission before launching anything).

If the homepage property points to an .zip or .exe-file - user should
automatically be asked to download/open the file directly (at least in
IE3 and later).

Then add some way that the user may call the Execute method (fx. a
button). Check the return value and inform the user if an internet
connection could not be made.

*)


interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;


{ Import function from Wininet.dll - this has been left out of Inprises
(Borlands) official import unit. Shame, Shame, Shame...
}
function InternetAttemptConnect(dwReserved:DWord):dword; stdcall;

{ Then the component itself
}
type
TUpdateEvent = procedure (Sender:TObject;var Launch:boolean) of object;

type
TChkUpdate = class(TComponent)
private
{ Private declarations }
fAutoProxy : boolean;
fURL : string;
fHomepage : string;
fRevision : integer;
fVersion : string;
fThreaded : boolean;
fOnFound : TUpdateEvent;
fOnNotFound : TNotifyEvent;
fOnNoConnect : TNotifyEvent;
// procedure SetVersion(Value:string);
// function GetVersion:string;
protected
procedure ChkResult(WebVer:double;WebRev:integer);
function ThreadExecute:boolean;
function BlockingExecute:boolean;
public
{ Methods }
constructor Create(AnOwner:TComponent); override;
function IsConnected:boolean;
function Execute:boolean;
published
{ Properties }
property AutoProxy : boolean read fAutoProxy write fAutoProxy;
property Homepage : string read fHomepage write fHomepage;
property Revision : integer read fRevision write fRevision;
property Threaded : boolean read fThreaded write fThreaded;
property URL : string read fURL write fURL;
property Version : string read fVersion write fVersion;
{ Events }
property OnFound : TUpdateEvent read fOnFound write fOnFound;
property OnNotFound : TNotifyEvent read fOnNotFound write fOnNotFound;
property OnNoConnect: TNotifyEvent read fOnNoConnect write fOnNoConnect;
end;

{ ------- -------- -------- -------- -------- -------- -------- ------- }

TChkResult = procedure(WebVer:double;WebRev:integer) of object;

{ ------- -------- -------- -------- -------- -------- -------- ------- }

TThreadedChecker = class(TThread)
private
{ Private declarations }
anURL : string;
aFlag : DWORD;
fVer : double;
fRev : integer;
fCallBack : TChkResult;
procedure ReturnResult;
protected
procedure Execute; override;
constructor Create(flags:integer;URL:string;Callback:TChkResult);
end;

procedure Register;


implementation
uses
Wininet, ShellApi;

{ ------- -------- -------- -------- -------- -------- -------- ------- }

 
多人接受答案了。
 
后退
顶部