下载论坛页面, 需要cookie认证, 请问怎样把cookie加进去? 我想下载一个论坛的某页面,但是这个论坛要求必须先登录才能访问内部的页面, 我使用了TidHttp组件来下载页面,看它的help说应该与TidCookieManager配合使用。我的IE里面已经记录了这个论坛的cookie ,但是直接用TidHttp.Get来下载就是不行,请问哪位仁兄知道具体的操作过程? 最好能给出源代码,谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 搞了几天,终于有了点眉目,以下是我登录一个asp站点的delphi程序,使用了IDHttp控件和IDCookieManager控件,在delphi7(带indy9)+win2k pro调试通过。有不当之处请指正,如转载请注明作者:yannqi。1、网站asp程序:判断如果有cookie显示用户名和邮件;如果没有将获得的用户名和邮件写入cookie。<%if (request.Cookies("name")="" or request.Cookies("email")="") then Response.Cookies("name") = request("name") Response.Cookies("email") = request("email") Response.write(request("name")+","+request("email")+",写入cookie")elseResponse.write("Name:"+request.Cookies("name"))Response.write("<br>email:"+request.Cookies("email"))end if%>2、delphi formobject Form1: TForm1 Left = 258 Top = 154 Width = 650 Height = 388 Caption = 'Form1' Color = clBtnFace Font.Charset = DEFAULT_CHARSET Font.Color = clWindowText Font.Height = -11 Font.Name = 'MS Sans Serif' Font.Style = [] OldCreateOrder = False PixelsPerInch = 96 TextHeight = 13 object btnLogin: TButton Left = 256 Top = 24 Width = 75 Height = 25 Caption = '提交' TabOrder = 0 OnClick = btnLoginClick end object edtUserName: TLabeledEdit Left = 0 Top = 24 Width = 121 Height = 21 EditLabel.Width = 50 EditLabel.Height = 13 EditLabel.Caption = 'UserName' TabOrder = 1 Text = 'yannqi' end object edtPassword: TLabeledEdit Left = 128 Top = 24 Width = 121 Height = 21 EditLabel.Width = 25 EditLabel.Height = 13 EditLabel.Caption = 'Email' TabOrder = 2 Text = '[email protected]' end object Memo1: TMemo Left = 312 Top = 64 Width = 321 Height = 281 Lines.Strings = ( 'Memo1') TabOrder = 3 end object Cookies: TMemo Left = 8 Top = 64 Width = 297 Height = 281 Lines.Strings = ( 'Cookies') TabOrder = 4 end object btnInfor: TButton Left = 336 Top = 24 Width = 75 Height = 25 Caption = '测试' TabOrder = 5 OnClick = btnInforClick end object Button3: TButton Left = 416 Top = 24 Width = 43 Height = 25 Caption = '清空' TabOrder = 6 OnClick = Button3Click end object http: TIdHTTP MaxLineAction = maException ReadTimeout = 0 AllowCookies = False ProxyParams.BasicAuthentication = False ProxyParams.ProxyPort = 0 Request.ContentLength = -1 Request.ContentRangeEnd = 0 Request.ContentRangeStart = 0 Request.ContentType = 'text/html' Request.Accept = 'text/html, */*' Request.BasicAuthentication = False Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)' HTTPOptions = [hoForceEncodeParams] CookieManager = CookieMngr Left = 120 Top = 96 end object CookieMngr: TIdCookieManager Left = 152 Top = 96 endend3、unit1。pasunit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, IdCookieManager, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;type TForm1 = class(TForm) http: TIdHTTP; CookieMngr: TIdCookieManager; edtUserName: TLabeledEdit; edtPassword: TLabeledEdit; btnLogin: TButton; Cookies: TMemo; Memo1: TMemo; btnInfor: TButton; Button3: TButton; procedure btnLoginClick(Sender: TObject); procedure btnInforClick(Sender: TObject); procedure Button3Click(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btnLoginClick(Sender: TObject);var s, s1: TStringStream; i: Integer;begin s := TStringStream.Create(''); s1 := TStringStream.Create(''); try s.WriteString('name=' + edtUserName.Text + '&'); s.WriteString('email=' + edtPassword.Text); http.Request.ContentType := 'application/x-www-form-urlencoded'; try http.Post('http://localhost/cookietest.asp', s, s1) except http.Get(http.Response.Location, s1); end; //} Memo1.Lines.Text := s1.DataString;//下面的是显示cookies信息的代码 Cookies.Clear; Cookies.Lines.Add(inttostr(CookieMngr.CookieCollection.Count)); for i := 0 to CookieMngr.CookieCollection.Count - 1 do Cookies.Lines.Add(CookieMngr.CookieCollection.Items[i].CookieText); finally s.Free; s1.Free; end;end;procedure TForm1.btnInforClick(Sender: TObject);var s, s1: TStringStream; i: Integer;begin s := TStringStream.Create(''); s1 := TStringStream.Create(''); try http.Request.ContentType := 'application/x-www'; http.AllowCookies:=true; try http.Post('http://localhost/cookietest.asp', s, s1) except http.Get(http.Response.Location, s1); end; Memo1.Lines.Text := s1.DataString; Cookies.Clear; for i := 0 to CookieMngr.CookieCollection.Count - 1 do Cookies.Lines.Add(CookieMngr.CookieCollection.Items[i].CookieText); finally s.Free; s1.Free; end;end;procedure TForm1.Button3Click(Sender: TObject);begincookies.Clear;Memo1.Clear;end;end. 你下载一个IEcooiesview,再找一个cooie欺骗的教程,就可以了 如何使用ADOQuery向Access和SQL Server插入数据 blazingfire 来回答问题拿分吧 招人:东莞虎门 简单问题,我却不会!! 有没有关于发邮件的API函数?请赐教…… 与大家探讨并请教几个有意思的问题,请诸位多发言。谢谢 数据库能不能用dll啊? 大家对《Delphi XML权威指南》的评价怎样? VAI转换成DVD(DAT)文件格式?? 书上的范例为什么不能运行? 紧急求救:在打开Frame的设计视图时老是提示TabOrder错误,怎么回事? 读取DFM窗口内容。
判断如果有cookie显示用户名和邮件;如果没有将获得的用户名和邮件写入cookie。
<%
if (request.Cookies("name")="" or request.Cookies("email")="") then Response.Cookies("name") = request("name")
Response.Cookies("email") = request("email")
Response.write(request("name")+","+request("email")+",写入cookie")
else
Response.write("Name:"+request.Cookies("name"))
Response.write("<br>email:"+request.Cookies("email"))
end if
%>2、delphi form
object Form1: TForm1
Left = 258
Top = 154
Width = 650
Height = 388
Caption = 'Form1'
Color = clBtnFace
Font.Charset = DEFAULT_CHARSET
Font.Color = clWindowText
Font.Height = -11
Font.Name = 'MS Sans Serif'
Font.Style = []
OldCreateOrder = False
PixelsPerInch = 96
TextHeight = 13
object btnLogin: TButton
Left = 256
Top = 24
Width = 75
Height = 25
Caption = '提交'
TabOrder = 0
OnClick = btnLoginClick
end
object edtUserName: TLabeledEdit
Left = 0
Top = 24
Width = 121
Height = 21
EditLabel.Width = 50
EditLabel.Height = 13
EditLabel.Caption = 'UserName'
TabOrder = 1
Text = 'yannqi'
end
object edtPassword: TLabeledEdit
Left = 128
Top = 24
Width = 121
Height = 21
EditLabel.Width = 25
EditLabel.Height = 13
EditLabel.Caption = 'Email'
TabOrder = 2
Text = '[email protected]'
end
object Memo1: TMemo
Left = 312
Top = 64
Width = 321
Height = 281
Lines.Strings = (
'Memo1')
TabOrder = 3
end
object Cookies: TMemo
Left = 8
Top = 64
Width = 297
Height = 281
Lines.Strings = (
'Cookies')
TabOrder = 4
end
object btnInfor: TButton
Left = 336
Top = 24
Width = 75
Height = 25
Caption = '测试'
TabOrder = 5
OnClick = btnInforClick
end
object Button3: TButton
Left = 416
Top = 24
Width = 43
Height = 25
Caption = '清空'
TabOrder = 6
OnClick = Button3Click
end
object http: TIdHTTP
MaxLineAction = maException
ReadTimeout = 0
AllowCookies = False
ProxyParams.BasicAuthentication = False
ProxyParams.ProxyPort = 0
Request.ContentLength = -1
Request.ContentRangeEnd = 0
Request.ContentRangeStart = 0
Request.ContentType = 'text/html'
Request.Accept = 'text/html, */*'
Request.BasicAuthentication = False
Request.UserAgent = 'Mozilla/3.0 (compatible; Indy Library)'
HTTPOptions = [hoForceEncodeParams]
CookieManager = CookieMngr
Left = 120
Top = 96
end
object CookieMngr: TIdCookieManager
Left = 152
Top = 96
end
end3、unit1。pas
unit Unit1;interfaceuses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdCookieManager, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP;type
TForm1 = class(TForm)
http: TIdHTTP;
CookieMngr: TIdCookieManager;
edtUserName: TLabeledEdit;
edtPassword: TLabeledEdit;
btnLogin: TButton;
Cookies: TMemo;
Memo1: TMemo;
btnInfor: TButton;
Button3: TButton;
procedure btnLoginClick(Sender: TObject);
procedure btnInforClick(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}
procedure TForm1.btnLoginClick(Sender: TObject);
var
s, s1: TStringStream;
i: Integer;
begin
s := TStringStream.Create('');
s1 := TStringStream.Create('');
try
s.WriteString('name=' + edtUserName.Text + '&');
s.WriteString('email=' + edtPassword.Text);
http.Request.ContentType := 'application/x-www-form-urlencoded'; try
http.Post('http://localhost/cookietest.asp', s, s1)
except
http.Get(http.Response.Location, s1);
end;
//}
Memo1.Lines.Text := s1.DataString;
//下面的是显示cookies信息的代码
Cookies.Clear;
Cookies.Lines.Add(inttostr(CookieMngr.CookieCollection.Count));
for i := 0 to CookieMngr.CookieCollection.Count - 1 do
Cookies.Lines.Add(CookieMngr.CookieCollection.Items[i].CookieText);
finally
s.Free;
s1.Free;
end;end;procedure TForm1.btnInforClick(Sender: TObject);
var
s, s1: TStringStream;
i: Integer;
begin
s := TStringStream.Create('');
s1 := TStringStream.Create('');
try
http.Request.ContentType := 'application/x-www';
http.AllowCookies:=true;
try
http.Post('http://localhost/cookietest.asp', s, s1)
except
http.Get(http.Response.Location, s1);
end;
Memo1.Lines.Text := s1.DataString;
Cookies.Clear;
for i := 0 to CookieMngr.CookieCollection.Count - 1 do
Cookies.Lines.Add(CookieMngr.CookieCollection.Items[i].CookieText);
finally
s.Free;
s1.Free;
end;end;procedure TForm1.Button3Click(Sender: TObject);
begin
cookies.Clear;
Memo1.Clear;
end;end.