Autor Beitrag
MrFreeze
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 19



BeitragVerfasst: Sa 13.10.07 16:26 
Hallo,

ich mlchte für mich ganz privat nen Proxy Programmieren(schon alleine zu lernzwecken).

Habe auch schon einiges Erreicht. Aber leider habe ich 2 Probleme, die das ganze Projekt zum fallen bringen.

a) habe ich eine Seite deren Formulardaten mittels Post verschickt werden - so passiert nichts! komme wieder auf die selbe Seite

noch schlimmer.

b) die Cookies die im IE gespeichert sind (zb Logins etc) funktionieren nicht mehr!


hier mal mein Code
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  LURL: string;
  LMethod: TIdHTTPMethod;
  LSource, LDest: TStream;
  LHTTP: TIdHTTP;
  S: string;
  i: integer;
begin
  {LURL := 'http://' + ARequestInfo.Host + ARequestInfo.Document;

  Label1.Caption := ARequestInfo.Host;
  Label2.Caption := ARequestInfo.Document;

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

  Memo1.Lines.Add(LURL);



  Label3.Caption := LURL;
  Label4.Caption := ARequestInfo.Command;


 }


  LSource := nil;
  LDest := nil;

 { if ARequestInfo.Command = 'GET' then
  begin
    LMethod := hmGet;
  end
  else
    if ARequestInfo.Command = 'POST' then
    begin
      LMethod := hmPost;
    end
    else
      if ARequestInfo.Command = 'HEAD' then
      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;  }



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

  AResponseInfo.ContentStream := TMemoryStream.Create;



//  LHTTP := TIdHTTP.Create(nil);
//  LHTTP.HandleRedirects := True;


  LHTTP := TIdHTTP.Create(nil);
  with LHTTP do
  begin
  //  Request.Assign(ARequestInfo);
    HandleRedirects := true;
    AllowCookies := true;
    CookieManager := TIdCookieManager.Create(LHTTP);
  end;


  if ARequestInfo.Command = 'POST' then
  begin
    Memo1.TExt := ARequestInfo.FormParams;
    LHTTP.Post('http://' + ARequestInfo.Host + ARequestInfo.Document + '?' + ARequestInfo.QueryParams, AResponseInfo.ContentStream);
  end
  else
    if ARequestInfo.Command = 'GET' then
      LHTTP.Get('http://' + ARequestInfo.Host + ARequestInfo.Document + '?' + ARequestInfo.QueryParams, AResponseInfo.ContentStream)
    else
    begin
      ShowMessage(ARequestInfo.Command);
      Exit;
    end;


  AResponseInfo.ContentType := LHTTP.Response.ContentType;
  AResponseInfo.ContentLength := AResponseInfo.ContentStream.Size;
  AResponseInfo.ResponseNo := LHTTP.ResponseCode;
  AResponseInfo.ServerSoftware := LHTTP.Response.Server;

  AResponseInfo.WriteHeader;
  AResponseInfo.WriteContent;

  AResponseInfo.ContentStream.Free;

 // 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);


      for i := 0 to LHTTP.CookieManager.CookieCollection.Count - 1 do
        AResponseInfo.Cookies.AddCookie(LHTTP.CookieManager.CookieCollection.Items[i]);

      AResponseInfo.ContentType := LHTTP.Response.ContentType;
      AResponseInfo.ServerSoftware := LHTTP.Response.Server;
      AResponseInfo.WriteHeader;
      AResponseInfo.WriteContent;
      AResponseInfo.ContentStream.Free;  }


  LHTTP.Free;
//    end;
 // except
 // end;
end;