如何在Delphi 2007中的密码保护位置下载文件 [英] How to download a file in a password-protected location in Delphi 2007

查看:127
本文介绍了如何在Delphi 2007中的密码保护位置下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从Web获取HTML页面的内容,但是只有在用户登录网站后才能使用相关资源的内容。

I need to get the contents of a HTML page from the Web, but the contents of the respective resource is only available after the user has logged into the website.

更具体地说,我需要下载在YouTube上被标记为不合适的视频文件的HTML页面。我有登录凭据,但我不知道如何继续登录。

To be more specific, I need to download the HTML page of a video file that has been flagged as inappropriate on Youtube. I do have the login credentials, but I'm not sure on how to proceed with the login.

我目前正在使用Synapse的HTTPSend下载非密码保护的HTML页面,而且我还在上一个项目中使用了Clever Internet Suite 7的授权副本

I'm currently downloading non-password-protected HTML pages with HTTPSend from Synapse, and I also have a licensed copy of Clever Internet Suite 7 I used in a previous project.

我使用的代码看起来像这样(这是严格信息的,如果需要,我可以改变方法):

The code I'm using looks like that (this is strictly informative, I can change the approach if necessary):

function GetHTMLFile(s: string): string;
var
  sHTTPSource:TStringList;
  HTTP: THTTPSend;
begin
  try
    sHTTPSource := TStringList.Create;
    if HttpGetText(s, sHTTPSource) then
    begin
      result := sHTTPSource.Text;
    end;
  finally
    sHTTPSource.Free;
  end;
end;

我不希望你为我做所有的工作,但我真的很感激提示方向正确。

I don't expect you to do all the work for me, but I'd really appreciate a hint in the right direction.

推荐答案

THTTPSend有一个属性.Cookies(TStringList),它取名称值对(每个都是一个cookie)。如果您使用相同的THTTPSend实例通过登录过程发布,则从YouTube发送的Cookie将被捕获,并将在以后的请求中使用相同的THTTPSend实例保留。您可以每次(获取新的Cookie)或在将请求转发给受保护的页面之前,将硬盘(或软)代码到THTTPSend中。

THTTPSend has a property .Cookies (TStringList) which takes name-value pairs (each one being a cookie). If you use the same THTTPSend instance to post through the login procedure then the cookies sent from YouTube will be captured and will be retained in future requests using the same THTTPSend instance. You can either do this each time (getting a new cookie) or you can hard (or soft) code the cookie information into the THTTPSend before making the request to the protected page.

您也可以一次登录并将.cookies TStringList保存在某处,每次将其分配到您创建的任何新THTTPSend以创建新请求。

You can also just do the login once and save the .cookies TStringList somewhere, each time assigning it to any new THTTPSend you create to make new requests.

这篇关于如何在Delphi 2007中的密码保护位置下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆