如何在Delphi 2007中的受密码保护的位置下载文件

时间:2021-12-17 00:36:19

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.

我需要从Web获取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.

更具体地说,我需要下载在Youtube上被标记为不当的视频文件的HTML页面。我确实有登录凭据,但我不确定如何继续登录。

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.

我目前正在使用来自Synapse的HTTPSend下载非密码保护的HTML页面,而且我还拥有我之前项目中使用的Clever Internet Suite 7的许可副本。

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.

我不指望你为我做所有的工作,但我真的很欣赏正确方向的暗示。

1 个解决方案

#1


3  

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.

THTTPSend有一个属性.Cookies(TStringList),它采用名称 - 值对(每个都是一个cookie)。如果您使用相同的THTTPSend实例发布登录过程,则将捕获从YouTube发送的cookie,并将使用相同的THTTPSend实例保留在将来的请求中。您可以每次执行此操作(获取新cookie),也可以在向受保护页面发出请求之前将cookie信息硬编码(或软编码)到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.

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

#1


3  

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.

THTTPSend有一个属性.Cookies(TStringList),它采用名称 - 值对(每个都是一个cookie)。如果您使用相同的THTTPSend实例发布登录过程,则将捕获从YouTube发送的cookie,并将使用相同的THTTPSend实例保留在将来的请求中。您可以每次执行此操作(获取新cookie),也可以在向受保护页面发出请求之前将cookie信息硬编码(或软编码)到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.

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