如何用Delphi实现在网页上下载文件。 如何用Delphi实现在网页上下载文件。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以使用http控件的post或是send函数 或者使用FastNet\NMFTP來通過FTP上傳文件 unit Unit1;interfaceuses 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 }{ [email protected] } //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. 求购一本旧书,Delphi6 SOAP Web Service程序设计篇! 怎么复制一个表 关于还原数据库备份文件的问题。 如何将相对路径转换为绝对路径 拜托各位帮我解决一个简单问题,急!急!急! 普通的DELPHI程序员请进来回答一下我的问题? 数据库问题求救。。。。。。。在线等待!!!!!!!急急急。。。。 为什么鼠标左键不能触发MouseDown事件?苦恼啊!!!! 如何根据盘符取得物理驱动器 --用Ado控件能连接Paradox的表吗?--- 请高手赐教 请问如何在DELPHI里把数值转化成中文大写数值?如把198转化成壹佰玖拾捌?
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 }
{ [email protected] }
//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.