0

I am using Delphi 7 and require some help with a problem, and yes, I have searched everywhere for an answer, yet the supplied code isn't documented , so I have no idea how it works or how to adjust it to fit my needs.

What I am trying to achieve is to log in to the website http://kissanime.com/login ..

The problem I'm experiencing is that I need to stay logged in while my program does some work on that website's HTML ( Basically I want to parse out the download links of a certain series, but I need to be logged in to view said links )...

I have no code that I can supply as none of the code that I saw while searching for a solution didn't make much sense, however, I have an idea of what needs to be done. I think that using some POST method to the website to supply it with the username and password would be a start, from there on out, I'm not sure whether or not I'd stay logged in.

I may be overcomplicating this problem and there is perhaps a simple way of achieving this, and that is why I have turned to the one site that I usually get all my answers from, I hope that I explained the problem well enough and that I can find some help..

I Do not expect source code , since I did not supply any here, but even some useful links that could explain this process to me would be much appreciated.

Here I have created a simple collage of images to just solidify my explanation of the problem :

enter image description here

Thank you for your time and I hope that I can find some clarity on this subject!

TLama
  • 75,147
  • 17
  • 214
  • 392
Kazuto Kirigaya
  • 93
  • 1
  • 3
  • 13
  • 1
    I think you just need to attach a `TIdCookie` to your `TIdHTTP` object. Cookies are usually used to store your session. If you don't supply one on your request after logging in, the website will redirect you to login page again. – GabrielF Mar 02 '15 at 15:12
  • Thanks for this , I will test this as soon as possible, so the only problem that persists now is that I need a way to send the initial login request to the site... – Kazuto Kirigaya Mar 02 '15 at 18:22
  • You don't "*attach a `TIdCookie` to your `TIdHTTP`*" (maybe you are thinking of `TIdCookieManager` instead?). You first `Get()` the webpage that contains the webform and let it generate whatever cookie(s) it needs and let `TIdHTTP` capture it/them (if you do not attach a `TIdCookieManager`, `TIdHTTP` creates one internally), then `Post()` the desired webform data to the appropriate webpage and `TIdHTTP` will include any relevant cookie(s) it is currently holding. – Remy Lebeau Mar 02 '15 at 21:38

1 Answers1

2

You need to first Get() the webpage that contains the webform and let it generate whatever cookie(s) it needs, and let TIdHTTP capture it/them (if you do not attach a TIdCookieManager to the TIdHTTP.CookieManager property, TIdHTTP creates a TIdCookieManager internally), then you can submit the desired webform data to the appropriate webpage and TIdHTTP will include any relevant cookie(s) it is currently holding. For example:

// get cookies first...
IdHTTP1.Get('http://kissanime.com/login');

// now submit the webform...
Params := TStringList.Create;
try
  Params.Add('username=' + UserName);
  Params.Add('password=' + Password);
  Params.Add('chkRemember=1'); // <-- omit this if you do not want to enable the webform's "Remember me" option
  Params.Add('btnSubmit=');
  Params.Add('redirect=');

  IdHTTP1.Post('http://kissanime.com/login', Params);
finally
  Params.Free;
end;
Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
  • I tried your solution, and when I run the code, I get a HTTP/1.1 403 Forbidden error? – Kazuto Kirigaya Mar 03 '15 at 22:45
  • edit : I resolved the 403 error by adding this : `IdHTTP1.Request.UserAgent := 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0';` – Kazuto Kirigaya Mar 03 '15 at 22:50
  • Thank you for this, for some reason ( even though your code was similar to other code I saw ) I understand these better, Only question I have is that whether this login will be for the remainder of the programs lifespan ( till I close it ) – Kazuto Kirigaya Mar 03 '15 at 22:57
  • The login will persist until you logout or the server ends the HTTP session on its own, whichever occurs first. As long you keep making HTTP requests to the server using the same login/cookie, the HTTP session should stay alive. But once you stop sending requests, the server is going to timeout eventually. HTTP is a state-less protocol, and does not require persistent TCP connections between requests (that is primarily why HTTP cookies exist - to persist data across non-persistent connections. HTML5's *local storage* is trying to replace cookies as the preferred persistence system). – Remy Lebeau Mar 04 '15 at 00:55
  • Thanks for the explanation, and thanks for solving my problem, I appreciate it :D – Kazuto Kirigaya Mar 04 '15 at 04:58