Registriert seit: 3. Jan 2007
Ort: Dresden
3.443 Beiträge
Delphi 7 Enterprise
|
Re: http GET Request per TSocket senden und Response empfang
2. Mär 2010, 16:02
Delphi-Quellcode:
uses
windows,
winsock;
// aus WinSock2
type WSAevent=THandle;
function WSACreateEvent:WSAEvent;stdcall;
external 'ws2_32.dll' name 'WSACreateEvent';
function WSACloseEvent(hEvent:WSAevent):bool;stdcall;
external 'ws2_32.dll' name 'WSACloseEvent';
function WSAResetEvent(hEvent: WSAEvent):bool;stdcall;
external 'ws2_32.dll' name 'WSAResetEvent';
function WSAEventSelect(s:TSocket;hEventObject:WSAevent;lNetworkEvents:LongInt):Integer; stdcall;
external 'ws2_32.dll' name 'WSAEventSelect';
function WSAWaitForMultipleEvents(cEvents:DWord;
lphEvents:Pointer;
fWaitAll:bool;
dwTimeOUT:DWord;
fAlertable:bool):DWord;stdcall;
external 'ws2_32.dll' name 'WSAWaitForMultipleEvents';
var
SockAddr1:TSockAddr= (sin_family:af_Inet;
sin_port:$5000; //=80
sin_addr:(S_addr:$C49F4B3E)); //=62.75.159.196
const WSA_WAIT_EVENT_0 = WAIT_OBJECT_0;
procedure main;
var wsaData:TwsaData;
SockEvent:WSAEvent;
Socket1:TSocket;
WSAresult:Integer;
buf:array[0..511] of char;
s:string;
begin
WSAStartUp(MakeWord(2,0),WSAData);
Socket1:=Socket(af_Inet,Sock_Stream,IPProto_TCP);
Connect(Socket1,SockAddr1,sizeof(TSockAddr));
SockEvent:=WSACreateEvent;
WSAEventSelect(Socket1,SockEvent,FD_Read);
s:='GET /download/index.php HTTP/1.1 '+#13#10+
'Host: blumenhund.afischi.de'+#13#10+
'Connection: close'+#13#10+
'User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'+#13#10+
'Accept-Encoding: gzip'+#13#10+
'Accept-Charset: ISO-8859-1,UTF-8;q=0.7,*;q=0.7'+#13#10+
'Cache-Control: no'+#13#10+
'Accept-Language: de,en;q=0.7,en-us;q=0.3'+#13#10#13#10;
send(Socket1,s[1],length(s),0);
repeat
WSAResult:=WSAWaitForMultipleEvents(1,@SockEvent,false,infinite,false);
case WSAResult of
WSA_WAIT_EVENT_0 : begin
fillchar(buf,sizeof(buf),0);
recv(Socket1,buf,512,0);
write(buf);
end;
else
break;
end;
WSAresetEvent(SockEvent);
until false;
WSACloseEvent(SockEvent);
WSACleanUp;
end;
begin
main;
end.
Macht. Müsste aber auch über Messages gehen.
Dieser Beitrag ist für Jugendliche unter 18 Jahren nicht geeignet.
|
|
Zitat
|