
16.12.2010, 10:04
|
 |
Let Me Show You
|
|
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
|
|
когда-то я так это дело писал. отправляет сообщения в чат форума (не этого!!!). при нажатии на кнопку с начала логинимся (можно тожа в потоке  ), потом создаем потоки TPostThread для каждого сообщения из мемы1. в мему2 добавляются отправленые сообщения для контроля.
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdTCPConnection,
IdTCPClient, IdHTTP, IdCookieManager;
type
TPostThread = class(TThread)
private
FMsg: String;
FSleep: Cardinal;
procedure Updt;
protected
procedure Execute; override;
public
constructor Create(AMsg: String; ASleep: Cardinal);
end;
TForm1 = class(TForm)
EditUser: TEdit;
EditPass: TEdit;
IdHTTP: TIdHTTP;
Button1: TButton;
IdCookieManager: TIdCookieManager;
Memo1: TMemo;
Memo2: TMemo;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
FSecuritytoken: String = '';
FCookie: String = '';
implementation
{$R *.dfm}
function StringToHex(s: String): String;
var
i: Integer;
begin
Result:='';
for i:=1 to Length(s) do Result:=Result+'%'+IntToHex(Ord(s[i]), 2);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
stringstream: TStringStream;
s: String;
i: Integer;
begin
stringstream:=TStringStream.Create('vb_login_username='+StringToHex(EditUser.Text)+'&vb_login_password='+StringToHex(EditPass.Text)+'&cookieuser=1&s=&securitytoken=guest&do=login&vb_login_md5password=&vb_login_md5password_utf=');
try
IdHTTP.Request.ContentType:='application/x-www-form-urlencoded';
IdHTTP.Request.ContentLength:=stringstream.Size;
IdHTTP.Post('http://forum.ru/login.php?do=login', stringstream);
IdHTTP.Request.ContentType:='';
IdHTTP.Request.ContentLength:=-1;
s:=IdHTTP.Get('http://forum.ru/index.php');
i:=Pos('<input type="hidden" name="securitytoken" value="', s);
if i>0 then
begin
s:=Copy(s, i+49, Length(s));
s:=Copy(s, 1, Pos('"', s)-1);
if (s<>'') and (s<>'guest') then
begin
FSecuritytoken:=s;
FCookie:='';
for i:=0 to IdCookieManager.CookieCollection.Count-1 do
FCookie:=FCookie+IdCookieManager.CookieCollection.Items[i].CookieName+'='+IdCookieManager.CookieCollection.Items[i].Value+'; ';
FCookie:=Trim(FCookie);
for i:=0 to Memo1.Lines.Count-1 do TPostThread.Create(Memo1.Lines[i], i*5000);
end;
end;
finally
stringstream.Free;
end;
end;
{ TPostThread }
constructor TPostThread.Create(AMsg: String; ASleep: Cardinal);
begin
inherited Create(True);
FreeOnTerminate:=True;
FMsg:=AMsg;
FSleep:=ASleep;
Resume;
end;
procedure TPostThread.Execute;
var
IdHTTP: TIdHTTP;
stringstream: TStringStream;
begin
Sleep(FSleep);
try
IdHTTP:=TIdHTTP.Create(nil);
IdHTTP.Request.CustomHeaders.Text:='Cookie: '+FCookie;
IdHTTP.HandleRedirects:=True;
IdHTTP.Request.ContentType:='application/x-www-form-urlencoded';
IdHTTP.Request.ContentLength:=stringstream.Size;
stringstream:=TStringStream.Create('do=shout&message='+StringToHex(FMsg)+'&securitytoken='+FSecuritytoken);
try
IdHTTP.Post('http://forum.ru/infernoshout.php', stringstream);
finally
stringstream.Free;
IdHTTP.Free;
end;
except
end;
Synchronize(Updt);
end;
procedure TPostThread.Updt;
begin
Form1.Memo2.Lines.Add(FMsg);
end;
end.
http://data.cod.ru/80218
__________________
Пишу программы за еду.
__________________
|