给点IDHTTP的资料~来者有分! (200分)

  • 主题发起人 主题发起人 东门飚血
  • 开始时间 开始时间

东门飚血

Unregistered / Unconfirmed
GUEST, unregistred user!
INDY9中IDHTTP的资料
包括.使用HTTP代理.取得COOKIE,下载文件.等等.(我要用来对付ASP)
一切资料.直接贴或者给联接都行~急用~
大富翁的全文检索又打不开~唉~
 
看看这里:
http://www.indyproject.org/
 
有没有中文的啊.应用实例~文字资料,都可以的~
 
帮你顶!
 
Delphi高手突破 看吗?
http://www.delphijs.net/Soft_Show.asp?SoftID=1782
 
我来了~~~~
 
book:
Delphi 7网络应用开发
 
继续~gyh75,你说的那本书里没有关于indy方面的东东~
qiulp 朋友说的是官方网站..[:(]
aimeoo 高手突破里也没有.
 
好像idhttp不支持cookie啊

以下可以实现文件下载!我是这样用的。。。^_^
Http.get就可以了。
var
MemStm: TMemoryStream;
begin
MemStm := TMemoryStream.create;
try
IDHttp.Get(url,..,MemStm);
MemStm.SaveToFile();
finally
Memstm.free;
end;
end;

在具体一点。。。
-----------
procedure DownFile(sName, DName: string);
var
Response: TFileStream;
HttpDown: TIdHTTP;
begin
HttpDown := TIDHttp.Create(nil);
try
HttpDown.Request.ProxyPort := 80;
HttpDown.Request.ContentType := 'application/x-www-form-urlencoded';
Response := TFileStream.Create(DName, fmCreate);
try
HttpDown.Get(sName, response);
finally
Response.Free;
end;
finally
HttpDown.free;
end;
end;
 
procedure TForm1.Button1Click(Sender: TObject);
const
DFW_LOGIN_URL = 'http://www.delphibbs.com/delphibbs/chkuser.asp';
UserName = '你的用户名';
Password = '你的密码'; //晕,刚才把密码写出来了,得改一下了
var
Params: TStrings;
HTML: String;
begin
Params:=TStringList.Create;
try
Params.Add('URL='+'/delphibbs/collections.asp');
//登录成功后跳转到的URL,这里直接转到"我收藏的问题"
Params.Add('QUERY_STRING='); //登录成功后跳转URL的参数
Params.Add('txtName='+UserName);
Params.Add('txtPass='+Password);
//Params.Add('chkSave='); //是否记住我的密码

IdHttp.HandleRedirects:=True;
HTML:=IdHttp.Post(DFW_LOGIN_URL,Params);
if Pos('<USER Name="" />',HTML)>0 then
ShowMessage('登录失败!') //登录失败则用户名为空
else
ShowMessage('登录成功!');
//分析HTML,取出每一条收藏贴子的URL,下载保存
finally
Params.Free;
end;
end;

楼上说的idhttp支持cookie 需要另一个控件。IdCookieManager1

我又一个下载网站网页的例子
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdHTTP, StdCtrls, IdIntercept, IdLogBase, IdLogDebug,IniFiles;

type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
ListBox1: TListBox;
Edit1: TEdit;
Edit2: TEdit;
IdHTTP1: TIdHTTP;
Edit3: TEdit;
Edit4: TEdit;
Button2: TButton;
ComboBox1: TComboBox;
Button3: TButton;
Button4: TButton;
procedure Button1Click(Sender: TObject);
procedure IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
procedure Button2Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Button3Click(Sender: TObject);
procedure Button4Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
inif:tinifile;
blink,link,endlink,artlink,endartlink,title,endtitle:string;
page:integer;
implementation

{$R *.dfm}
function CountSubStr(const SubStr,endsubstr, Source: string; var str:tstringlist): integer; // 注意,必须加const或者var关键字
var
i, n, len1, len2,m: Integer;
st:string;

begin
result := 0;
i := 1;
n:=0;
len1 := Length(SubStr);
len2 := Length(Source)-len1+1;
while (i <=len2)and (result<20) and (n>=0) do
begin
n := pos(SubStr, string(@Source)); // 这里的技巧是高效的关键, 直接将上一次找到的位置作为字符串的起始传入pos函数
m := pos(endsubstr,string(@Source[i+n])); //这样取字符串会产生问题///
if n > 0 then

begin
inc(result);
st:=copy(string(@Source),n+len1,m-len1);//length(endsubstr));//n+26,5);//这个是csdn的
str.Add(st);
inc(i, n+len1-1);
end
else break;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var astr:AnsiString;
str1:tstringlist;
i:integer;
st:string;
pagecount:integer;
begin
pagecount:=strtoint(edit2.text);
st:=edit1.Text;
str1:=tstringlist.Create;
for i:=1 to pagecount do
begin
astr:= idhttp1.Get(st+inttostr(i));

if countsubstr(artlink,endartlink,astr,str1) >0 then ;
end;
listbox1.Items:=str1;
for i:=0 to listbox1.Count-1 do
begin
memo1.Lines.Text:=idhttp1.Get('http://www.csdn.net/develop/Read_Article.asp?Id='+listbox1.Items.Strings);
memo1.Lines.SaveToFile('d:/'+listbox1.items.Strings+'.htm');
end;
//showmessage(copy(astr,pos('href="Read_Article.asp?Id=',astr)+26,5));
//copy(astr,pos('href="Read_Article.asp?Id=',astr),10)
//memo1.Lines.Text:=astr;
end;

procedure TForm1.IdHTTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
//showmessage('');
end;

procedure TForm1.Button2Click(Sender: TObject);
var astr:AnsiString;
strl:tstringlist;
i:integer;
st:string;
pagecount:integer;
begin
pagecount:=strtoint(edit4.text);
st:=edit3.Text;
strl:=tstringlist.Create;
for i:=1 to pagecount do
begin
astr:= idhttp1.Get(st+inttostr(i));
if countsubstr(artlink,endartlink,astr,strl) >0 then;
end;
listbox1.Items:=strl;
for i:=0 to strl.Count-1 do
begin
memo1.Lines.Text:=idhttp1.Get('http://www.codelphi.com/channel/hjwz/read.asp?ano='+strl.Strings);
memo1.Lines.SaveToFile('d:/'+strl.Strings+'.htm');
end;
end;

procedure TForm1.FormCreate(Sender: TObject);

begin
inif:=tinifile.create('d:/htmchm.ini');
Inif.ReadSections(ComboBox1.Items);
combobox1.ItemIndex:=0;
{
inif.ReadSection();//读取一节的数据
inif.WriteString('csdn','sdfaa','asdfasdfasf');
inif.ReadString(csdn,)
inif.ReadSection('csdn',strs);
}

end;

procedure TForm1.Button3Click(Sender: TObject);
var astr:AnsiString;
str1:tstringlist;
i:integer;
st:string;
pagecount:integer;
begin
link:=inif.ReadString(combobox1.Text,'link','');//最后面的常量字符串做什么用?/a索引页连接
endlink:=inif.ReadString(combobox1.Text,'endlink','');//
artlink:=inif.ReadString(combobox1.Text,'artlink','');//文章标识连接
endartlink:=inif.ReadString(combobox1.Text,'endartlink','');
title:=inif.ReadString(combobox1.Text,'title','');//文章名称标题连接
endtitle:=inif.ReadString(combobox1.Text,'endtitle','');
page:=inif.Readinteger(combobox1.Text,'page',0);
blink:=inif.ReadString(combobox1.Text,'blink','');
//读取ini文件信息到对应的变量中//
pagecount:=page;
st:=link;
str1:=tstringlist.Create;
for i:=1 to pagecount do
begin
astr:= idhttp1.Get(st+inttostr(i));//st+inttostr(i)为对应的网址
try
if countsubstr(artlink,endartlink,astr,str1) >0 then ;
except
showmessage('去文件标号错误');
end;
end;
listbox1.Items:=str1;
for i:=0 to listbox1.Count-1 do
begin
//memo1.Lines.Text:=idhttp1.Post(blink+listbox1.Items.Strings,'co.txt');
memo1.Lines.Text:=idhttp1.Get(blink+listbox1.Items.Strings);
memo1.Lines.SaveToFile('d:/'+listbox1.items.Strings+'.htm');
end;

end;

procedure TForm1.Button4Click(Sender: TObject);
begin
idhttp1.Post('http://www.codelphi.com/channel/forum/showmessage.asp','co.txt',EmptyParam);
end;

end.

 
有没有关于TCPclient方面的资料?
 
后退
顶部