Thema: Delphi Proxy probleme

Einzelnen Beitrag anzeigen

delphinia

Registriert seit: 16. Feb 2006
444 Beiträge
 
Delphi 11 Alexandria
 
#1

Proxy probleme

  Alt 11. Okt 2007, 19:50
Nutzte idHTTPServer und idHTTP als Proxy-Lösung.
Habe hier ne menge beispiele für sowas gefunden.

derzeiiger Code:

Delphi-Quellcode:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent, IdComponent,
  IdTCPServer, IdCustomHTTPServer, IdHTTPServer, IdTCPConnection,
  IdTCPClient, IdHTTP, StdCtrls;

type
  TForm1 = class(TForm)
    IdHTTPServer1: TIdHTTPServer;
    IdAntiFreeze1: TIdAntiFreeze;
    Label1: TLabel;
    ListBox1: TListBox;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    procedure IdHTTPServer1CreatePostStream(ASender: TIdPeerThread;
      var VPostStream: TStream);
    procedure IdHTTPServer1CommandGet(AThread: TIdPeerThread;
      ARequestInfo: TIdHTTPRequestInfo;
      AResponseInfo: TIdHTTPResponseInfo);
  private
    { Private-Deklarationen }

  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}


procedure TForm1.IdHTTPServer1CreatePostStream(ASender: TIdPeerThread; var VPostStream: TStream);
begin
        // creating our own stream so that TIdHTTPServer does not automatically
        // free the PostStream before the OnCommandGet event is triggered
  VPostStream := TMemoryStream.Create;
end;

procedure TForm1.IdHTTPServer1CommandGet(AThread: TIdPeerThread; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  LHTTP: TIdHTTP;
  LURL: string;
  LMethod: TIdHTTPMethod;
  LSource, LDest: TStream;
begin
  LURL := 'http://' + ARequestInfo.Host;


  Label1.Caption := LURL;
  Label2.Caption := LURL + '?' + ARequestInfo.QueryParams;
  Label3.Caption := ARequestInfo.Command;


  begin

    LSource := nil;
    LDest := nil;

    if ARequestInfo.Command = 'GETthen
    begin
      LMethod := hmGet;
    end
    else
      if ARequestInfo.Command = 'POSTthen
      begin
        LMethod := hmPost;
      end
      else
        if ARequestInfo.Command = 'HEADthen
        begin
          LMethod := hmHead;
        end
        else
        begin
          AResponseInfo.ResponseNo := 501; // not implemented
          Exit;
        end;

    if LMethod <> hmHead then
    begin
      AResponseInfo.ContentStream := TMemoryStream.Create;
      if LMethod = hmPost then
        LSource := ARequestInfo.PostStream;
      LDest := AResponseInfo.ContentStream;
    end;


    if Length(ARequestInfo.QueryParams) > 0 then
    begin
      LURL := LURL + '?' + ARequestInfo.QueryParams;
    end;

    LHTTP := TIdHTTP.Create(nil);
    try
      try
        LHTTP.DoRequest(LMethod, LURL, LSource, LDest);
      finally
        AResponseInfo.ResponseNo := LHTTP.Response.ResponseCode;
        AResponseInfo.ResponseText := LHTTP.Response.ResponseText;
        AResponseInfo.RawHeaders.Assign(LHTTP.Response.RawHeaders);
                // copy over anything else that is needed...
        LHTTP.Free;
      end;
    except
    end;
  end;
end;

end.


Leider werden wie auf dem Bild zu sehen alle möglichen wichtigen dinge nicht durch den Proxy übernommen oder weitergegeben
zb. Bilder, CSS, Cookies etc....

Wo liegt der Fehler??!
Miniaturansicht angehängter Grafiken
delphipraxis_113.jpg  
Doreen
Gruss Doreen
  Mit Zitat antworten Zitat