Indy 10中的TIdHTTP [英] TIdHTTP in Indy 10
问题描述
我曾经在Delphi中使用Indy 6天,现在我正在使用Indy 10.我想做的事情非常简单,但是我看不到这样做的简单方法,因此我一定会缺少一些东西.
I used to use Indy back in the Delphi 6 days, and I am playing with Indy 10 now. What I want to do is incredibly simple, but I don't see a simple way of doing it, so I must be missing something.
我想做的是这样的:
这是我正在使用的实际代码:
Here is the actual code I am using:
procedure TForm1.btnGetURLClick(Sender: TObject);
begin
moHeader.Lines.Clear;
moBody.Lines.Clear;
try
moBody.text := IdHttp1.Get(edURL.text);
finally
end;
end;
请求完成后,http_result应该包含来自指定URL的HTML.但是,这似乎不起作用,所以我觉得我应该使用IOHandler属性或组件的OnWork事件-但是用法对我而言似乎并不明显,并且我找不到任何有效的示例与谷歌.我确信这是以前做过的事情,因此将不胜感激.
When the request is complete, the http_result should contain the HTML from the URL specified. This doesn't seem to work however, so I get the feeling I should perhaps be using the IOHandler property or the OnWork event of the component - however the usage doesn't seem obvious to me, and I couldn't find any working examples with google. I am sure this is something that has been done before, so any help would be appreciated.
其他信息: 本着更加具体的精神,我想知道: 1.我是否一开始就这样做(或者我错过了什么?). 2.如果是这样,为什么它不起作用. 3.我正在使用的compile/os/Indy组合中总是有bug的. (尽管它应该可以工作).
Additional Information: In the spirit of being more specific, I want to know: 1. Am I doing this right to begin with (or did I miss something?). 2. If so, why might it not be working. 3. It is always possible that there is a bug in the combination of compiler/os/Indy I am using. (Although it should be working).
我应该提到的是,我总是会弹出一个连接正常关闭"的弹出窗口.这似乎是一个例外,它可能会干扰函数的结果.我试图用TRY ... FINALLY捕获它,但是它不起作用.我猜想可能是因为Indy在运行Get方法之后在后台触发了异常.
I should mention, I always get a popup "Connection Closed Gracefully". This seems to be an exception, and it could be interfering with the result of the function. I attempted to trap this with a TRY...FINALLY, but it doesn't work. Probably because Indy is triggering the exception in the background after the Get method runs I suppose.
最后,这是正在运行的程序的屏幕截图,以清除任何混乱: http://screencast.com/t/NDMzNTQ5 我希望HTML可以填充第二个备注框.
Finally, here is a screencast of the program running to clear up any confusion: http://screencast.com/t/NDMzNTQ5 I expect the HTML to fill the second memo box.
推荐答案
Another option, would be to use synapse. This is all that is needed to retrieve a webpage using this library:
uses
...,HTTPSEND;
var
Result : TStrings;
if HTTPGetText('http://www.google.com',Result) then
// do something with result
Synapse是轻量级的TCPIP库.该库正在积极维护中,当前版本在Delphi 2009/2010中运行良好.它不是基于组件的框架,因此很容易与其他线程技术一起使用( OmniThreadLibrary 或 AsyncCalls ).
Synapse is a lightweight TCPIP library. The library is being actively maintained and the current version runs fine in Delphi 2009/2010. It is NOT a component based framework, so it is very easy to use with other threading techniques (OmniThreadLibrary or AsyncCalls for example).
这篇关于Indy 10中的TIdHTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!