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
|
procedure TForm1.ConnectClick(Sender: TObject);
var
i:integer;
begin
loginurl:='http://212.100.209.7/security/Login.aspx?culture=ar';
Params := TStringList.Create;
try
cookies:=tstringlist.Create;
html:=idhttp1.Get(loginurl);
count:=IdCookieManager1.CookieCollection.count;
for i:=1 to count do
cookies.Add(IdCookieManager1.CookieCollection.Items[i-1].CookieText);
html:=idhttp1.Get(loginUrl);
poz:=pos('name="__VIEWSTATE" value="',html);
delete(html,1,poz+25);
viewstate:=copy(html,1,pos('"',html)-1);
Params.Values['__VIEWSTATE'] := viewstate;
Params.Values['TxtUsername'] := '------';
Params.Values['TxtPassword'] := '******';
Params.Values['BtnLogin'] := 'Login';
setCookies;
IdHTTP1.HandleRedirects:=false;
try
HTML := IdHTTP1.Post(loginurl, Params);
except on e: EIdHTTPProtocolException do
begin
if e.ReplyErrorCode<>302 then
raise e;
count:=IdCookieManager1.CookieCollection.count;
for i:=1 to count do
cookies.Add(IdCookieManager1.CookieCollection.Items[i-1].CookieText);
setcookies;
html:=idhttp1.Get(IdHTTP1.Response.Location);
memo1.Lines.add(IdHTTP1.Get('http://212.100.209.7/Security/MainPage.aspx'));
end;
end;
except on e: EIdHTTPProtocolException do
begin
memo2.lines.add(idHTTP1.response.ResponseText);
memo3.lines.add(e.ErrorMessage);
end;
end;
Params.Free; |