如何用Delphi实现在网页上下载文件。

jtww888 2003-06-28 10:47:25
如何用Delphi实现在网页上下载文件。
...全文
166 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
Debug007 2003-06-29
  • 打赏
  • 举报
回复
unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
ComCtrls, StdCtrls, Psock, NMHttp, ExtCtrls, jpeg;

type
TForm1 = class(TForm)
NMHTTP1: TNMHTTP;
Button1: TButton;
Label1: TLabel;
edtURL: TEdit;
StatusBar1: TStatusBar;
Label2: TLabel;
lblTemp: TLabel;
Label4: TLabel;
lblFinal: TLabel;
procedure Button1Click(Sender: TObject);
procedure NMHTTP1Success(Cmd: CmdType);
procedure FormCreate(Sender: TObject);
procedure NMHTTP1Failure(Cmd: CmdType);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.Button1Click(Sender: TObject);
begin
NMHTTP1.Get(edtURL.text);
end;

procedure TForm1.NMHTTP1Success(Cmd: CmdType);
var
fname:string;
buf:string;
pnewfile,poldfile:pchar;
i:integer;
begin
{ Copyright (C) Bowman }
{ MatthewBowman@21cn.com }
//retrive the tmp file
fname:=nmhttp1.body;
//retrive file name
for i:=length(edtURL.Text) downto 1 do
if edtURL.text[i]<>'/' then
buf:=edtURL.text[i]+buf
else
break;
//assign file name
Getmem(poldFile,length(fname)+1);
StrPCopy(poldFile,fname);
Getmem(pnewfile,length(buf)+1);
StrPCopy(pnewfile,buf);
//rename it
MoveFile(poldfile,pnewfile);
Freemem(poldfile);
Freemem(pnewfile);
//show infomation
statusbar1.Panels.Items[0].text:='download complete';
lblTemp.caption:= fname;
lblFinal.Caption:=buf;


end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//store in file
NMHTTP1.InputFileMode:= TRUE;
NMHTTP1.TimeOut:=2000;
//set temp file name
NMHTTP1.Body:='Part.tmp';
NMHTTP1.Header:='Head.tmp';
end;

procedure TForm1.NMHTTP1Failure(Cmd: CmdType);
begin
StatusBar1.Panels.Items[0].text:='Failed';
end;

end.
Eastunfail 2003-06-28
  • 打赏
  • 举报
回复
或者使用FastNet\NMFTP來通過FTP上傳文件
fengjn 2003-06-28
  • 打赏
  • 举报
回复
可以使用http控件的post或是send函数

5,927

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧