2012-01-02 31 views
11

Delphi 2007からDelphi XEにコードを移植しようとしています(まだ更新1はありません)。私が遭遇した問題は、Delphi XEの下では、2番目のGETメッセージを送信した後にサーバーから異なる応答を得ているということです。TIdHTTP - Delphi XEでセッションの有効期限が切れたメッセージ

フォーマットされたHTMLのメッセージは、セッションが終了したことを示しています。ただし、Delphi 2007では今日まで同じコードが問題なく動作します。私はインターネット上で情報を検索し、CookieManagerを使うべきであることを知りましたか?

私がDelphi 2007で何も使用していないことと、Delphi XEで割り当てたときに、私のコードの結果は変更されていないことです。それでも私は期限切れのセッションについてのメッセージを受け取ります。

他に何を試すことができますか?

更新:私は、インディ10がクッキーに問題があるという情報を見つけましたが、修正されました。

スナップショットIndy10_4722をダウンロードしましたが、残念ながらエラーが発生します。

アップデート2 - コードだから

を提供し、私は、サンプルコードを用意しました。これはDelphi(2007とXE)の両方と互換性があります。しかし2007年にコンパイルするにはGraphicEx libraryが必要です。

コードは実サーバに接続しており、セキュリティイメージをロードしてフォームに表示します。画像から編集ボックスに文字を書き換えて、フォームを閉じます。それはあなたがそれをテストするために必要なすべてです。デルファイ2007例are hereため

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. 

アップデート3

データパケット。

デルファイのデータパケット例are here

無料のパケット解析プログラムSmartSniff

ありがとうございました。

+0

を参照してください。でも、私の質問ミスターにお答えください! ;-) – Wodzu

+3

'TIdHTTP'は自分自身を提供していない場合、暗黙の' TIdCookieManager'オブジェクトを内部的に使います。 Indy 10の古いスナップショットにはいくつかのCookie関連の問題がありましたが、現代のスナップショットは2011年にリリースされた新しいCookie RFCに基づいた完全に再設計されたCookie処理システムを備えています。依然としてCookieの問題があると思われる場合は、実際のCookieとその周囲の関連するHTTP要求/応答トラフィックを確認して、Cookieがいつサーバーに返されるかを確認する必要があります。 –

+0

ありがとうございました、今日は完全な実例と完全な比較例を提供します。 – Wodzu

答えて

1

httpanalyzerfiddlerなどのツールを使用してリクエストを検査することを検討する必要があります。

最初にInternet Explorerを使用して、要求がどのように行われるかを確認します。

次に、アプリを使用して両方のリクエストを比較します。それがクッキーの問題であれば、何が間違っているかがわかります。

キープアライブはあなたの答えではありません。それは、あなたが同じリクエストに対する各リクエストでドロップされないようにするだけです。 Wikipedia

関連する問題