10.12.2013, 19:31
|
Прохожий
|
|
Регистрация: 07.02.2012
Сообщения: 45
Репутация: 10
|
|
Цитата:
Сообщение от poli-smen
После успешного залогонивания сервер тебе должен вернуть куки (Cookies) их нужно запомнить и последующие запросы отправлять вместе с этими куками - именно так работают браузеры и другие качалки умеющие логониться.
Т.е. смотри свойство THTTPSend.Cookies
|
Сделал как было предложено, в итоге и в методе POST и в методе GET используются одни и те же куки
Код:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, httpsend, ssl_openssl, StdCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
mmo1: TMemo;
edt1: TEdit;
procedure btn1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function FoundLocationStrNum(Headers: TStringlist): integer;
var
FoundStrPos, i: integer;
begin
Result := -1;
for i := 0 to Headers.Count do
begin
FoundStrPos := Pos('Location: ', Headers.Strings[i]);
if FoundStrPos > 0 then
begin
Result := i;
exit;
end;
end;
end;
function GetHTTPStr(http: THTTPSend): string;
var
BodyStream: TStringStream;
BodyS: TStringList;
begin
try
BodyS := TStringList.Create;
BodyStream := TStringStream.Create(result);
begin
BodyS.LoadFromStream(http.Document);
result := BodyS.Text;
end;
finally
BodyStream.Free;
BodyS.Free;
end;
http.Document.Seek(0, soFromBeginning);
end;
procedure TForm1.btn1Click(Sender: TObject);
var
httpsend: THTTPSend;
stream: TStringStream;
str: TstringList;
n: integer;
NewURL, result: string;
Res: boolean;
begin
str:=TstringList.Create;
httpsend:= THTTPSend.Create;
stream := TStringStream.Create('');
stream.WriteString('mode=login&username=***&password=***&remember=1');
Application.ProcessMessages;
httpsend.MimeType := 'application/x-www-form-urlencoded';
httpsend.Document.LoadFromStream(stream);
Res := httpsend.HTTPMethod('post', 'http://pikabu.ru/ajax/ajax_login.php');
str.Text:=httpsend.Cookies.Text;
httpsend.Clear;
httpsend.Cookies.Text:=str.Text;
httpsend.HTTPMethod('GET', edt1.Text);
Application.ProcessMessages;
mmo1.Text:=Utf8ToAnsi(GetHTTPStr(httpsend));
end;
end.
но выгружает совсем не то, что хотелось бы...
Цитата:
<html>
<!--LiveInternet counter--><script type="text/javascript"><!--
new Image().src = "http://counter.yadro.ru/hit?r"+
escape(document.referrer)+((typeof(screen)=="undef ined")?"":
";s"+screen.width+"*"+screen.height+"*"+(screen.co lorDepth?
screen.colorDepth:screen.pixelDepth))+";u"+escape( document.URL)+
";h"+escape(document.title.substring(0,80))+
";"+Math.random();//--></script><!--/LiveInternet-->
<body onload="challenge();">
<script>
eval(function(p,a,c,k,e,r){e=function(c){return c.toString(a)};if(!''.replace(/^/,String)){while(c--)r[e(c)]=k[c]||e(c);k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('1 6(){2.3=\'4=5; 0-7=8; 9=/\';a.b.c()}',13,13,'max|function|document|cookie|p hpsessien|821a5a2cc0ed0ec3e9829084c1ae2d3be7e2108e |challenge|age|43200|path|window|location|reload'. split('|'),0,{}))
</script>
</body>
</html>
|
В чем может быть проблема? Может из-за того, что я Гет в начале перед логином не делаю? Это вообще критично?
|