Delphi-从代码登录网页 [英] Delphi - logging in to webpage from code
问题描述
我正在使用Delphi 7,需要一些问题的帮助,是的,我到处都在寻找答案,但是所提供的代码没有记录在案,所以我不知道它是如何工作的或如何将其调整为符合我的需求.
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.
我要实现的目标是登录网站 http://kissanime.com/login ..
What I am trying to achieve is to log in to the website http://kissanime.com/login ..
我遇到的问题是,当我的程序在该网站的HTML上执行某些工作时,我需要保持登录状态(基本上,我想解析某个系列的下载链接,但是我需要登录到查看所说的链接)...
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 )...
我没有可以提供的代码,因为我在寻找解决方案时看到的代码都没有多大意义,但是,我对需要完成的工作有所了解.我认为,使用某种POST方法在网站上为其提供用户名和密码将是一个开始,从那以后,我不确定是否要保持登录状态.
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 :
谢谢您的时间,希望我能在这个问题上找到一些清晰的认识!
Thank you for your time and I hope that I can find some clarity on this subject!
推荐答案
您需要先Get()
包含该Webform的网页,并使其生成所需的任何cookie,然后让TIdHTTP
捕获它/它们(如果您没有将TIdCookieManager
附加到TIdHTTP.CookieManager
属性,TIdHTTP
在内部创建了TIdCookieManager
),则可以将所需的Webform数据提交到适当的网页,并且TIdHTTP
将包括任何相关的cookie当前持有的(s).例如:
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;
这篇关于Delphi-从代码登录网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!