![]() |
|
|
|
|
#1
|
|||
|
|||
|
Есть delphi xe2 пытаюсь авторизироватся на одном сайте с помощью компонента IdHTTP1 + IdSSLIOHandlerSocketOpenSSL1 (POST запрос ) авторизация как бы проходит с idHTTP1.Response.ResponseText = 'HTTP/1.1 302 Moved Temporarily' как правильно обрабатывать перенаправления (Header(Location : ............ ) в php ) также подключил куки менеджер но после запроса он (Form1.IdCookieManager1) пуст хотя в IdHTTP1.Response.RawHeaders.Text 'Set-cookie' ну и сами куки присутствуют. Пытался вручную вытащит куки и подставить в IdHTTP1.Request.RawHeaders.AddStrings('.....'); после чего GET запросом получить уже html код но не получается ...
Код:
procedure TForm1.Button5Click(Sender: TObject);
var
s:string;
i:integer;
LoginInfo: TStringList;
Response: TStringStream;
begin
LoginInfo := TStringList.Create;
Response := TStringStream.Create('');
IdHTTP1.AllowCookies := True;
IdHTTP1.HandleRedirects := True;
IdHTTP1.CookieManager := Form1.IdCookieManager1;
Form1.IdHTTP1.Request.CustomHeaders.Clear;
Form1.IdHTTP1.Request.CustomHeaders.Add('POST /XXX/YY.php?m=login HTTP/1.1');
Form1.IdHTTP1.Request.Accept:='text/html, application/xhtml+xml, */*';
Form1.IdHTTP1.Request.Referer:='https://37.X.X.X/XXX/YY.php?m=login';
Form1.IdHTTP1.Request.AcceptLanguage:='ru-RU';
Form1.IdHTTP1.Request.UserAgent:='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
Form1.IdHTTP1.Request.ContentType:= 'application/x-www-form-urlencoded';
Form1.IdHTTP1.Request.AcceptEncoding := 'gzip, deflate';
Form1.IdHTTP1.Request.Host := '37.X.X.X';
//Content-Length 24
Form1.IdHTTP1.Request.Connection := 'Keep-Alive';
Form1.IdHTTP1.Request.CacheControl := 'no-cache';
LoginInfo.Add('user=my_user');
LoginInfo.Add('pass=my_pass');
Form1.IdHTTP1.Post('https://37.X.X.X/XXX/YY.php?m=login',LoginInfo,Response);
showmessage(IdHTTP1.Response.RawHeaders.Text);
s:=idHTTP1.Response.ResponseText;
s:= IdHTTP1.Response.Location;
i:= IdHTTP1.Response.ResponseCode;
s:= IdHTTP1.Response.Server;
Form1.IdHTTP1.Request.CustomHeaders.Clear;
Form1.IdHTTP1.Request.CustomHeaders.Add('GET /XXX/YY.php?m=home HTTP/1.1');
Form1.IdHTTP1.Request.Accept:='text/html, application/xhtml+xml, */*';
Form1.IdHTTP1.Request.Referer:='https://37.X.X.X/XXX/YY.php?m=login';
Form1.IdHTTP1.Request.AcceptLanguage:='ru-RU';
Form1.IdHTTP1.Request.UserAgent:='Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)';
Form1.IdHTTP1.Request.ContentType:= 'application/x-www-form-urlencoded';
Form1.IdHTTP1.Request.AcceptEncoding := 'gzip, deflate';
Form1.IdHTTP1.Request.Host := '37.X.X.X';
Form1.IdHTTP1.Request.Connection := 'Keep-Alive';
Form1.IdHTTP1.Request.CacheControl := 'no-cache';
s:= Form1.IdHTTP1.Get('https://37.X.X.X/XXX/YY.php?m=home');
showmessage(IdHTTP1.Response.RawHeaders.Text);
s:=idHTTP1.Response.ResponseText;
s:= IdHTTP1.Response.Location;
i:= IdHTTP1.Response.ResponseCode;
s:= IdHTTP1.Response.Server;
Response.Free;
LoginInfo.Free;
end; |
|
#2
|
||||
|
||||
|
CustomHeaders и установка Host не нужны, метод и адрес Indy подставит в заголовки сам.
|
|
#3
|
|||
|
|||
|
а в чем может быть проблема ?
|
|
#4
|
||||
|
||||
|
Без нормального адреса не смогу проверить.
|