Entwickler-Ecke

Internet / Netzwerk - Indys Proxy


Comp-Freak - Mi 21.03.07 11:45
Titel: Indys Proxy
After lots of help I finnaly have a program wich should work as a proxy.
The problem is, as you may have guessed, it doesnt.
I tried this proxy on my own computer and all I got on my internet explorer is a white screen. After loading another page the proxy reported to have connected but then it hangs itself.
Here is the code:

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:
/////////////////////////////////////////////////
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdTCPServer, IdCmdTCPServer, IdHTTPProxyServer, IdBaseComponent,
  IdComponent, IdCustomTCPServer, IdCustomHTTPServer, IdHTTPServer, IdContext,
  IdTCPConnection, IdTCPClient, IdHTTP, StdCtrls;

type
  TForm1 = class(TForm)
    Server: TIdHTTPServer;
    HTTP: TIdHTTP;
    ListBox1: TListBox;
    GroupBox1: TGroupBox;
    Button1: TButton;
    Edit1: TEdit;
    Label1: TLabel;
    Label2: TLabel;
    Edit2: TEdit;
    CheckBox1: TCheckBox;
    CheckBox2: TCheckBox;
    procedure ServerCommandGet(AContext: TIdContext;
      ARequestInfo: TIdHTTPRequestInfo;
      AResponseInfo: TIdHTTPResponseInfo);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Button1Click(Sender: TObject);
    procedure ServerConnect(AContext: TIdContext);
    procedure ServerDisconnect(AContext: TIdContext);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ServerCommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
  URL, stuff: string;
begin
  URL := 'http://'+ARequestInfo.Host+ARequestInfo.Document;
  try
    while HTTP.Tag=1 do Application.ProcessMessages;
    HTTP.Tag:=1;
    stuff := HTTP.Get(URL);
    AResponseInfo.ContentText := stuff;
    AResponseInfo.ContentType := HTTP.Response.ContentType;
    HTTP.Tag:=0;
    application.ProcessMessages;
  except
    listbox1.Items.insert(0,'Error');
  end;
  listbox1.Items.Insert(0,URL+' Forwarded');
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
server.active := false;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
server.DefaultPort := strtoint(edit1.text);
server.maxconnections := strtoint(edit2.text);
if checkbox1.Checked = true then
 server.AutoStartSession := true;
if checkbox2.Checked = true then
 server.KeepAlive := true;
edit1.enabled := false;
button1.Enabled := false;
edit2.Enabled := false;
checkbox1.enabled := false;
checkbox2.enabled := false;
server.Active := true;
end;

procedure TForm1.ServerConnect(AContext: TIdContext);
begin
listbox1.Items.insert(0,'Connected');
end;

procedure TForm1.ServerDisconnect(AContext: TIdContext);
begin
listbox1.Items.insert(0,'Disconnected');
end;

end.
/////////////////////////////////////////////////

The settings i used for the proxy:
port: 80
max connections: 1
keep alive: no
auto start session: no
The settings of internet explorer>extras>options>connection>lan button>
port: 80
ip: 127.0.0.1

The log report of proxy/iexplorer:
proxy:connect
proxy:error
proxy:forwarded http://www.google.com
proxy:disconnect
iexplorer:blank page (no error just all white)
>>> I load other page/same page again.
proxy:connect
>>> proxy hangs itself and doesnt respond
>>> iexplorer shows error page (site not found bla bla bla please refresh bla bla bla)

i figured the problem is that my proxy sends back a blank package but it does send back something. Another problem could be that the proxy and the iexplorer are on the same comp. I have no idea what causes the error on the second time. i tried changing max connects but nothing changes.

plese help
(also it would be nice if someone could tell me how to post the code in a window.)
thanks

Moderiert von user profile iconTino: Delphi-Tags hinzugefügt


Narses - Mi 21.03.07 12:24

Moin!

Sag mal, warum schreibst du eigentlich mal Deutsch und mal Englisch... ? :gruebel:

Schonmal die Suche benutzt? ;) Suche in: Delphi-Forum, Delphi-Library PROXY

Code mit Syntaxhighlighting: im Editor den Code markieren und oben auf das "+" neben "Delphi" klicken. ;)

cu
Narses


Comp-Freak - Mi 21.03.07 12:31

hab die suche gar nicht gesehen ... war wohl zu voreilig =). Wenigstens hilft sie.

opps sorry ich verwechsle english und deutsch weil ich in japan lebe. Ich bin eigentlich ein schweitzer aber hab vier jahre nur noch english gesprochen... japanish lernen ist die holle, vorallem when der lehrer dich nicht versteht...


matze - Mi 21.03.07 12:57

du kannst auch die Indy Proxy Komponente nehmen. Die ist bei der Version 10 der Indys dabei. Damit hast du dann keine Probleme mehr.


Comp-Freak - Mi 21.03.07 13:43

bei der indy proxy componente, wenn ich starte und dann das hauptformular schlisse kommt dieser fehler: IdStackBSDBase und ich muss pfad angeben ...
auserdem habe ich gehort man kann nicht kontrolloieren was da durch geht ...
mein problem ist sowieso schon gelost =)


matze - Mi 21.03.07 17:32

und wie ist dein Problem gelößt?