Версия для печати темы
Нажмите сюда для просмотра этой темы в оригинальном формате
Форум программистов > Delphi: Сети > Как залогиниться на сайте?


Автор: MAQrus 28.1.2007, 21:06
Пытаюсь залогиниться на сайте. Читал форум, но так и не нашел ответ на свой вопрос. Как отправить запрос я вроде понял, но все время получается злополучная 302 ошибка. В чем дело не могу понять...

Код

 url := 'http://site.ru/register/login2.phtml?redirect=http://site.ru/index.phtml';
 s1 := TStringList.Create;
 s1.Add('login=login1');
 s1.Add('password=pass1');
 LinkXMemo4.Text := IdHTTP1.Post(url, s1);
 s1.Free;


Если логиниться браузером:

Код

GET /register/login2.phtml?redirect=http://site.ru/index.phtml&login=ww00&password=111111&auto= HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-icq, application/x-gsarcade-launch, */*
Accept-Language: ru
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon; Avant Browser; .NET CLR 1.1.4322)
Host: site.ru
Connection: Keep-Alive
Cookie: login=ww00; DELITID=78c1dfa567780b53af187e9ce97674dc; rtn4p=3

HTTP/1.1 302 Found
Server: nginx/0.5.8
Date: Sun, 28 Jan 2007 17:51:41 GMT
Content-Type: text/html; charset=windows-1251
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/4.4.2
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: login=ww00; expires=Tue, 27 Feb 2007 17:51:41 GMT; path=/
Set-Cookie: phpbb2mysql_sid=deleted; expires=Sat, 28 Jan 2006 17:51:40 GMT; path=/bb/
Set-Cookie: phpbb2mysql_data=deleted; expires=Sat, 28 Jan 2006 17:51:40 GMT; path=/bb/
Set-Cookie: phpbb2mysql_t=deleted; expires=Sat, 28 Jan 2006 17:51:40 GMT; path=/bb/
Location: http://site.ru/index.phtml
Content-Length: 0

GET /index.phtml HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-icq, application/x-gsarcade-launch, */*
Accept-Language: ru
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Maxthon; Avant Browser; .NET CLR 1.1.4322)
Host: site.ru
Connection: Keep-Alive
Cookie: login=ww00; DELITID=78c1dfa567780b53af187e9ce97674dc; rtn4p=3

HTTP/1.1 200 OK
Server: nginx/0.5.8
Date: Sun, 28 Jan 2007 17:51:41 GMT
Content-Type: text/html; charset=windows-1251
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/4.4.2
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache


Если программой:

Код

POST /register/login2.phtml?redirect=http://site.ru/index.phtml HTTP/1.0
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 26
Host: site.ru
Accept: text/html, */*
Accept-Encoding: identity
User-Agent: Mozilla/3.0 (compatible; Indy Library)

login=ww00&password=111111


Ошибка:

HTTP/1.1 302 Found


Я вроде догнал что нужно отправлять id сессии, но как получить ее их куков и отправить, не совсем понимаю...

Автор: creas0ft 28.1.2007, 21:19
302 Moved Temporarily
HandleRedirects :=True тебе поможет 

Автор: MAQrus 28.1.2007, 21:27
Спасибо!! Уже ошибки нет, посмотрим что дальше будет... smile

Автор: MAQrus 28.1.2007, 22:44
Не логинится все равно smile

Посмотрите плиз, могут ли быть какие-нибудь ошибки?  smile 


Код

 url := 'http://site.ru/register/login2.phtml?redirect=http://site.ru/index.phtml';
 s1 := TStringList.Create;
 s1.Add('login=login1');
 s1.Add('password=pass1');
 IdHTTP1.Post(url,s1);
 s1.Free;



программа выдает:
Код

POST /register/login2.phtml?redirect=http://site.ru/index.phtml HTTP/1.0
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Content-Length: 26
Host: site.ru
Accept: text/html, */*
Accept-Encoding: identity
User-Agent: Mozilla/3.0 (compatible; Indy Library)

login=ww00&password=111111HTTP/1.1 302 Found
Server: nginx/0.5.8
Date: Sun, 28 Jan 2007 19:24:43 GMT
Content-Type: text/html; charset=windows-1251
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/4.4.2
Set-Cookie: DELITID=3bed2ec590d33215b8413f331cd00119; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: http://site.ru/register/login2.phtml?redirect=http://site.ru/index.phtml&err=1
Content-Length: 0

GET /register/login2.phtml?redirect=http://site.ru/index.phtml&err=1 HTTP/1.0
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Host: site.ru
Accept: text/html, */*
Accept-Encoding: identity
User-Agent: Mozilla/3.0 (compatible; Indy Library)
Cookie: DELITID=3bed2ec590d33215b8413f331cd00119

HTTP/1.1 302 Found
Server: nginx/0.5.8
Date: Sun, 28 Jan 2007 19:24:44 GMT
Content-Type: text/html; charset=windows-1251
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/4.4.2
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: http://site.ru/index.phtml
Content-Length: 0

GET /index.phtml HTTP/1.0
Connection: keep-alive
Content-Type: application/x-www-form-urlencoded
Host: site.ru
Accept: text/html, */*
Accept-Encoding: identity
User-Agent: Mozilla/3.0 (compatible; Indy Library)
Cookie: DELITID=3bed2ec590d33215b8413f331cd00119

HTTP/1.1 200 OK


Браузер выдает:
Код

GET /register/login2.phtml?redirect=http://site.ru/index.phtml&login=ww00&password=111111 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-icq, application/x-gsarcade-launch, */*
Accept-Language: ru
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322)
Host: site.ru
Connection: Keep-Alive

HTTP/1.1 302 Found
Server: nginx/0.5.8
Date: Sun, 28 Jan 2007 19:35:16 GMT
Content-Type: text/html; charset=windows-1251
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/4.4.2
Set-Cookie: DELITID=4c6de88bbb22012fca8fbb82343319e9; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Location: http://site.ru/register/login2.phtml?redirect=http://site.ru/index.phtml&login=ww00&password=111111&err=1
Content-Length: 0

GET /register/login2.phtml?redirect=http://site.ru/index.phtml&login=ww00&password=111111&err=1 HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-icq, application/x-gsarcade-launch, */*
Accept-Language: ru
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322)
Host: site.ru
Connection: Keep-Alive
Cookie: DELITID=4c6de88bbb22012fca8fbb82343319e9

HTTP/1.1 302 Found
Server: nginx/0.5.8
Date: Sun, 28 Jan 2007 19:35:16 GMT
Content-Type: text/html; charset=windows-1251
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/4.4.2
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Set-Cookie: login=ww00; expires=Tue, 27 Feb 2007 19:35:16 GMT; path=/
Set-Cookie: phpbb2mysql_sid=deleted; expires=Sat, 28 Jan 2006 19:35:15 GMT; path=/bb/
Set-Cookie: phpbb2mysql_data=deleted; expires=Sat, 28 Jan 2006 19:35:15 GMT; path=/bb/
Set-Cookie: phpbb2mysql_t=deleted; expires=Sat, 28 Jan 2006 19:35:15 GMT; path=/bb/
Location: http://site.ru/index.phtml
Content-Length: 0

GET /index.phtml HTTP/1.1
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/x-icq, application/x-gsarcade-launch, */*
Accept-Language: ru
UA-CPU: x86
Accept-Encoding: gzip, deflate
User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Avant Browser; .NET CLR 1.1.4322)
Host: site.ru
Connection: Keep-Alive
Cookie: DELITID=4c6de88bbb22012fca8fbb82343319e9; login=ww00

HTTP/1.1 200 OK
Server: nginx/0.5.8
Date: Sun, 28 Jan 2007 19:35:16 GMT
Content-Type: text/html; charset=windows-1251
Transfer-Encoding: chunked
Connection: keep-alive
Keep-Alive: timeout=20
X-Powered-By: PHP/4.4.2
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache


Добавлено @ 22:47 
с куками точно ничего делать не нужно?

Автор: MAQrus 15.2.2007, 17:50
Оказалось всё крайне просто:
Код

SUPER_HTTP.HandleRedirects:=True;
S:= SUPER_HTTP.get('http://site.ru/register/login2.phtml?login='+login+'&password='+pass);

login,pass - стринги

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)