使用Indy&从受保护的网页获取html源时出现问题德尔福7 [英] Problem getting html source from a protected webpage with Indy & Delphi 7

查看:57
本文介绍了使用Indy&从受保护的网页获取html源时出现问题德尔福7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用用于phi的Indy10组件,我正在抓取网页的源代码,并使用以下代码将其显示在Memo控件中.

Using the Indy10 components for delp I am grabbing the source of a webpage and displaying it in a Memo control using the following code.


procedure TForm1.Button1Click(Sender: TObject);
begin
Memo1.Text := IdHTTP1.Get(Edit1.Text);
end;

当我尝试显示的页面只是普通页面(即无需登录)时,结果很好,但是,如果我尝试获取需要登录的页面的来源,则结果将显示备忘录登录页面的来源,而不是我请求的页面,尽管事实上我已经在Firefox和IE浏览器中都登录到了该网站.

When the page I am trying to display is just a normal page (ie. no login required) the results are fine, but if I try to grab the source of a page that requires a login then the result is the memo displays the source of the login page instead of the page I requested despite the fact that I am logged in to the site in both Firefox and IE browsers.

所以我的问题是如何使用Indy组件对网站进行身份验证",以便获得与登录后在浏览器中查看页面时获得的相同来源?

So my question is how can I "authenticate" myself with the site using the Indy components so I get the same source that I would get if I were to view the page in my browser after logging in ?

Thx,道格拉斯

推荐答案

您应该花一些时间来学习整个HTTP的工作原理,因为有时它比看起来要复杂.浏览器的功能远不止是简单地通过URL发出HTTP GET或POST请求,然后获取一些HTML.例如,由于HTTP标头携带许多有用的信息,因此它们存储了许多有关已访问站点的信息.他们的操作通常是特定于浏览器的,而不是系统范围的.其他浏览器或应用程序可能无法查看或使用它们.您必须为给定站点正确设置HTTP标头,并处理诸如身份验证之类的情况.带有身份验证的站点可以使用广泛的技术来允许访问,从简单的登录页面到HTTP身份验证方法.他们可以将您重定向到处理身份验证的页面,尽管对于已经登录的用户而言,身份验证可以透明地发生,但是浏览器(或应用程序)将看到正在发生的事情,并且必须进行处理.

You should take some time to learn how the whole HTTP thing works, because sometimes it is more complex than what it looks. A browser does a lot more than simply issuing HTTP GET or POST request with a URL, and getting back some HTML. For example they store a lot of informations about visited sites, because the HTTP headers carry a lot of useful informations. How they do it is usually browsers specific, and not system-wide. Other browser or applications may be not able to see or use them. You have to set up the HTTP headers properly for a given site, and handle situations like authentication. Sites with authentication can use broad range of techniques to allow access, from simple login pages to HTTP authentication methods. They can redirect you to pages that handle authentication, and although it can happen trasparently for an already logged user, a browser (or an application) will see what's happening and must handle that.

这篇关于使用Indy&从受保护的网页获取html源时出现问题德尔福7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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