菜鸟菜问题:)!!!!!!!!!!!!之六 (100分)

  • 主题发起人 主题发起人 yutao728
  • 开始时间 开始时间
Y

yutao728

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么用语言实现网上的一张图的下载 保存到本地
告诉我详细点 谢谢!
 
你可以下在大富翁论坛的离线浏览器,看看它的源码。
 
发个HTTP请求给这个图片的URL,然后保存数据流就是,
可以看TNMHTTP这个控件的用法
 
:吴剑明sir:
请给点详细说明!!!!!
多谢拉!!!
 
给你一段源代码,你要加上TNMHTTP这个控件.
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<>'/' then
buf:=edtURL.text+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.
 
好像没有那么复杂吧,
用NMHTTP.GET();
 

Similar threads

D
回复
0
查看
2K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
837
DelphiTeacher的专栏
D
D
回复
0
查看
793
DelphiTeacher的专栏
D
后退
顶部