TIdHTTP-Delphi XE下的会话已过期消息

TIdHTTP-Delphi XE下的会话已过期消息,delphi,port,delphi-xe,delphi-2007,indy,Delphi,Port,Delphi Xe,Delphi 2007,Indy,我正在尝试将我的代码从Delphi2007移植到DelphiXE(还没有更新1)。我偶然发现的问题是,在DelphiXE下,在发送第二条GET消息后,我从服务器得到了不同的响应 格式化HTML中的消息表示我的会话已过期。但是,到目前为止,在Delphi2007下,相同的代码仍然可以正常工作。我在互联网上搜索信息,发现我应该使用CookieManager 问题是,我没有在Delphi2007中使用任何代码,当我在Delphi XE中指定一个时,代码的结果没有改变。我仍然收到关于过期会话的消息 我还

我正在尝试将我的代码从Delphi2007移植到DelphiXE(还没有更新1)。我偶然发现的问题是,在DelphiXE下,在发送第二条GET消息后,我从服务器得到了不同的响应

格式化HTML中的消息表示我的会话已过期。但是,到目前为止,在Delphi2007下,相同的代码仍然可以正常工作。我在互联网上搜索信息,发现我应该使用CookieManager

问题是,我没有在Delphi2007中使用任何代码,当我在Delphi XE中指定一个时,代码的结果没有改变。我仍然收到关于过期会话的消息

我还能试什么

更新:我发现一些信息表明Indy 10的cookies存在问题,但问题已经解决

我已经在Indy10_4722下载了快照,不幸的是错误仍然发生

更新2-提供代码

所以,我准备了一个示例代码。这与Delphi(2007和XE)兼容。然而,要在2007年下编译它,您需要有

代码连接到真实的服务器,加载一个安全映像并在表单中显示它。将图像中的字母重写到编辑框中,然后关闭表单。这就是测试它所需要做的一切

program IndyTest;

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Contnrs, Menus, ExtCtrls, IdBaseComponent,
  IdComponent, IdTCPConnection, IdTCPClient, IdHTTP,
  {$IFDEF VER220}PngImage{$ELSE}GraphicEx{$ENDIF}, StrUtils;

{$R *.res}

procedure LoadSecurityImage(AImage: TImage; AIdHTTP: TIdHTTP; AImgLink: String);
var
  PNGGraphic: {$IFDEF VER220}TPngImage{$ELSE} TPNGGraphic{$ENDIF};
  ResponseStream: TMemoryStream;
begin
  ResponseStream := TMemoryStream.Create;
  PNGGraphic   := {$IFDEF VER220}TPngImage.Create{$ELSE}TPNGGraphic.Create{$ENDIF};
  try
    AIdHTTP.Get(AImgLink, ResponseStream);
    ResponseStream.Position := 0;
    PNGGraphic.LoadFromStream(ResponseStream);
    AImage.Picture.Assign(PNGGraphic);
  finally
    ResponseStream.Free;
    PNGGraphic.Free;
  end;
end;

function GetImageLink(AIdHTTP: TIdHTTP): String;
var
  WebContentStream: TStringStream;
  Index, Index2: Integer;
begin
  Result := '';
  WebContentStream := TStringStream.Create('');
  try
    AIdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
    AIdHTTP.Get('http://czat.wp.pl/i,1,chat.html', WebContentStream);
    Index := Pos('id="secImg">', WebContentStream.DataString);
    if Index > 0 then
    begin
      Index := PosEx('src="', WebContentStream.DataString, Index) + 5;
      Index2 := PosEx('">', WebContentStream.DataString, Index);
      if Index > 10 then
      begin
        Result := Copy(WebContentStream.DataString, Index, Index2 - Index);
      end;
    end;
  finally
    WebContentStream.Free;
  end;
end;

procedure CheckForContent(const ANick, AImageSeed: String; AIdHTTP: TIdHTTP);
var
  WebContent: TStringStream;
  S: String;
begin
  WebContent := TStringStream.Create('');
  try
    AIdHTTP.Request.ContentType := 'application/x-www-form-urlencoded';
    S := 'http://czat.wp.pl/chat.html?i=31179&auth=nie&nick=' + ANick
      + '&regulamin=tak&simg=' + AImageSeed + '&x=39&y=13';
    AIdHTTP.Get(S, WebContent);
    if Pos('<div class="applet">', WebContent.DataString) > 0 then
      ShowMessage('It works properly.')
    else if Pos('<div id="alert">Sesja wygas', WebContent.DataString) > 0 then
      ShowMessage('Session expired')
    else
      ShowMessage('Unknown result.');
  finally
    WebContent.Free;
  end;
end;

var
  LogForm: TForm;
  SecurityImage: TImage;
  Edit: TEdit;
  IdHTTPWp: TIdHTTP;
begin
  Application.Initialize;
  IdHTTPWp := TIdHTTP.Create(Application);
  IdHTTPWp.AllowCookies := True;
  IdHTTPWp.HandleRedirects := True;
  IdHTTPWp.HTTPOptions := [hoForceEncodeParams];

  LogForm := TForm.Create(Application);
  LogForm.Position := poScreenCenter;
  SecurityImage := TImage.Create(LogForm);
  SecurityImage.Parent := LogForm;
  SecurityImage.AutoSize := True;
  Edit := TEdit.Create(LogForm);
  Edit.Parent := LogForm;
  Edit.Top := 64;
  LoadSecurityImage(SecurityImage, IdHTTPWp, GetImageLink(IdHTTPWp));
  LogForm.ShowModal;
  CheckForContent('TestUser', Edit.Text, IdHTTPWp);
  Application.Run;
end.
程序索引测试;
使用
窗口、消息、系统工具、变体、类、图形、控件、窗体、,
对话框、StdCtrls、Contnrs、菜单、ExtCtrls、IdBaseComponent、,
IdComponent、IdTCPConnection、IdTCPClient、IdHTTP、,
{$IFDEF VER220}PngImage{$ELSE}GraphicEx{$ENDIF},StrUtils;
{$R*.res}
过程LoadSecurityImage(AImage:TImage;AIdHTTP:TIdHTTP;AImgLink:String);
变量
PNGGraphic:{$IFDEF VER220}TPngImage{$ELSE}TPNGGraphic{$ENDIF};
ResponseStream:TMemoryStream;
开始
ResponseStream:=TMemoryStream.Create;
PNGGraphic:={$IFDEF VER220}TPngImage.Create{$ELSE}TPNGGraphic.Create{$ENDIF};
尝试
获取(AImgLink,ResponseStream);
响应团队位置:=0;
PNGGraphic.LoadFromStream(ResponseStream);
目的.图片.分配(PNGGraphic);
最后
响应团队自由;
无图形;
结束;
结束;
函数GetImageLink(AIdHTTP:TIdHTTP):字符串;
变量
WebContentStream:TStringStream;
索引,Index2:整数;
开始
结果:='';
WebContentStream:=TStringStream.Create(“”);
尝试
AIdHTTP.Request.ContentType:=“应用程序/x-www-form-urlencoded”;
AIdHTTP.Get('http://czat.wp.pl/i,1,chat.html',WebContentStream);
索引:=Pos('id=“secImg”>',WebContentStream.DataString);
如果索引>0,则
开始
索引:=PosEx('src=“”,WebContentStream.DataString,Index)+5;
Index2:=PosEx(“>”,WebContentStream.DataString,Index);
如果索引>10,则
开始
结果:=复制(WebContentStream.DataString,Index,Index2-Index);
结束;
结束;
最后
WebContentStream.Free;
结束;
结束;
过程内容检查(const ANick,AImageSeed:String;AIdHTTP:TIdHTTP);
变量
网络内容:TStringStream;
S:字符串;
开始
WebContent:=TStringStream.Create(“”);
尝试
AIdHTTP.Request.ContentType:=“应用程序/x-www-form-urlencoded”;
S:='http://czat.wp.pl/chat.html?i=31179&auth=nie&nick=“+ANick
+“®ulamin=tak&simg=”+AImageSeed+”&x=39&y=13';
获取(S,WebContent);
如果Pos(“”,WebContent.DataString)>0,则
ShowMessage('它工作正常')
否则,如果Pos('Sesja wygas',WebContent.DataString)>0,则
ShowMessage('会话已过期')
其他的
ShowMessage('未知结果');
最后
网络内容。免费;
结束;
结束;
变量
对数型:TForm;
安全图像:TImage;
编辑:TEdit;
IdHTTPWp:TIdHTTP;
开始
应用程序初始化;
IdHTTPWp:=TIdHTTP.Create(应用程序);
IdHTTPWp.AllowCookies:=真;
IdHTTPWp.HandleRedirects:=True;
IdHTTPWp.HTTPOptions:=[hoForceEncodeParams];
LogForm:=TForm.Create(应用程序);
LogForm.Position:=位置中心;
SecurityImage:=TImage.Create(LogForm);
SecurityImage.Parent:=LogForm;
SecurityImage.AutoSize:=True;
编辑:=TEdit.Create(LogForm);
Edit.Parent:=LogForm;
编辑.Top:=64;
LoadSecurityImage(SecurityImage、IdHTTPWp、GetImageLink(IdHTTPWp));
LogForm.showmodel;
CheckForContent('TestUser',Edit.Text,IdHTTPWp);
应用程序。运行;
结束。
更新3

Delphi2007示例的数据包

delphixe示例的数据包

免费程序来分析数据包


谢谢。

< P>我认为你应该考虑使用像./P>之类的工具检查请求。 首先使用Internet Explorer,看看它是如何处理请求的

然后使用你的应用程序并比较两个请求。如果这是一个cookie问题,你会发现问题出在哪里


保持活力不是你的答案。它只会使您在每次请求同一服务器时不会断开连接。看

好的,我会的,但你最好回答我的问题,先生!;-)
TIdHTTP
在内部使用隐式
TIdCookieManager
对象(如果您自己没有提供)。Indy 10的旧快照确实存在一些与cookie相关的问题,但现代快照有一个完全重新设计的cookie处理系统,该系统基于2011年发布的新cookie RFC,据我所知,它在大多数已知系统中都能正常工作。如果您认为您仍然存在cookie问题,那么我们需要查看实际的cookie以及与之相关的HTTP请求/响应流量,以便我们可以查看cookie何时或何时被发送回服务器。谢谢,今天,我将提供一个完整的工作示例和一个完整的不工作示例进行比较。@Wodzu:按照时间顺序,HTTP状态管理机制的相关RFC是:(过时的),(过时的),并最终于2011年4月发布。Indy 10用于实现RFC 2109和2965,以及Netscape最初的cookie规范,其中没有RFC。现在它只实现了RFC6265,它涵盖了大多数mo需要的所有内容