Autor Beitrag
Sentinel85
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Do 27.03.08 02:16 
Hallo zusammen,
also ich habe mich mal etwas mit der Kommunikation zwischen Browser und Server beschäftigen wollen.
Ich habe also die TcpClient und TcpServer Komponente von Delphi genommen und wollte eine GET Anfragen machen (wie sie bei jedem Seitenaufruf der Browser macht). Leider bekomme ich keine Antwort vom Server...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
//------------------------------------------------------------------------------------------ 
TcpServer.RemotePort := '80'
TcpServer.Active := true; 
TcpClient.RemoteHost := 'de.wikipedia.org'
document := '/wiki/Walhall'
TcpClient.RemotePort := '80'
try 
if TcpClient.connect then 
TcpClient.sendln('GET' + ' ' + document + ' ' + 'HTTP/1.0' + #13#10#13#10); 
finally 
TcpClient.disconnect; 
//------------------------------------------------------------------------------------------ 
.TcpServerAccept 
s := ClientSocket.receiveln; 
while s <> '' do 
begin 
memo.Lines.add(s); 
s := ClientSocket.receiveln; 
end
//------------------------------------------------------------------------------------------

Hoffe mal das da wer weiter helfen kann - danke!
Gruß Sentinel

Moderiert von user profile iconNarses: Delphi-Tags hinzugefügt
Sentinel85 Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Do 27.03.08 21:39 
Habe mich nochmal auf die Suche gemacht, diesen Artikel von Narses gefunden
www.delphi-library.d...n+seit+D7_64438.html
und den TClientSocket reaktiviert um es mit dem nochmal zu probieren...

ausblenden 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:
edhost.text:de.wikipedia.org
eddoc.text:/wiki/Hauptseite

procedure .btsendClick(Sender: TObject);
begin
  ClientSocket.Port := 80;
  ClientSocket.Host := edhost.text;
  ClientSocket.Open;
end;

procedure .ClientSocketConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  //ClientSocket.Socket.SendText('GET' + ' ' + eddoc.text + ' ' + 'HTTP/1.0'); //keine Antwort
  //ClientSocket.Socket.SendText('GET' + ' ' + eddoc.text + ' ' + 'HTTP/1.0' + #13#10#13#10); //Antwort siehe unten
  //ClientSocket.Socket.SendText('GET' + ' ' + eddoc.text + ' ' + 'HTTP/1.1'); //keine Antwort
  //ClientSocket.Socket.SendText('GET' + ' ' + eddoc.text + ' ' + 'HTTP/1.1' + #13#10#13#10); //Antwort siehe unten
  //ClientSocket.Socket.SendText('POST' + ' ' + eddoc.text + ' ' + 'HTTP/1.0'); //keine Antwort
  //ClientSocket.Socket.SendText('POST' + ' ' + eddoc.text + ' ' + 'HTTP/1.0' + #13#10#13#10); //Antwort siehe unten
  //ClientSocket.Socket.SendText('POST' + ' ' + eddoc.text + ' ' + 'HTTP/1.1'); //keine Antwort
  //ClientSocket.Socket.SendText('POST' + ' ' + eddoc.text + ' ' + 'HTTP/1.1' + #13#10#13#10); //Antwort siehe unten
end;

procedure .ClientSocketRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  mequellcode.Lines.Add(ClientSocket.Socket.ReceiveText);
end;


Antwort ist:
HTTP/1.0 400 Bad Request
Server: squid/2.6.STABLE18
Date: Thu, 27 Mar 2008 19:30:09 GMT
Content-Type: text/html
Content-Length: 50107
Expires: Thu, 27 Mar 2008 19:30:09 GMT
X-Squid-Error: ERR_INVALID_REQ 0
X-Cache: MISS from knsq2.knams.wikimedia.org
X-Cache-Lookup: NONE from knsq2.knams.wikimedia.org:80
Via: 1.0 knsq2.knams.wikimedia.org:80 (squid/2.6.STABLE18)
Proxy-Connection: close

und eine Multilingual_error_messages
meta.wikimedia.org/w...ngual_error_messages

Aber warum?
Narses
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Administrator
Beiträge: 10185
Erhaltene Danke: 1261

W11x64
TP3 .. D7pro .. D10.2CE
BeitragVerfasst: Do 27.03.08 21:46 
Moin und :welcome: im Forum!

user profile iconSentinel85 hat folgendes geschrieben:
Antwort ist:
HTTP/1.0 400 Bad Request
Hier schonmal reingeschaut? ;)

cu
Narses

_________________
There are 10 types of people - those who understand binary and those who don´t.
Sentinel85 Threadstarter
Hält's aus hier
Beiträge: 3



BeitragVerfasst: Mi 02.04.08 01:11 
für die Nachwelt:
der request sieht so aus:

GET / HTTP/1.1\r\n
Host: www.google.de\r\n
\r\n

und so dann eben in Delphi
GET / HTTP/1.1 + #13#10 + 'Host: www.google.de' + #13#10 + #13#10;

ein Dankeschön geht an Narses