简体   繁体   English

如何为TIdHTTPProxyServer设置超时(不是连接超时)

[英]How do I set timeout for TIdHTTPProxyServer (not connection timout)

I am using TIdHTTPProxyServer and now I want to terminate connection when it is success to connect to the target HTTP server but receive no response for a long time(ig 3 mins) Currently I find no related property or event about it. 我正在使用TIdHTTPProxyServer,现在我想在成功连接到目标HTTP服务器时终止连接,但是很长一段时间都没有收到响应(ig 3分钟)。目前,我没有任何相关的属性或事件。 And even if the client terminate the connection before the proxy server receive the response from the HTTP server. 并且即使客户端在代理服务器收到来自HTTP服务器的响应之前终止连接。 OnException Event will not be fired until the proxy server receive the response. 在代理服务器收到响应之前,不会触发OnException事件。 (That is, if the proxy server still receive no response from HTTP Server, I even do not know the client has already terminate the connection...) (也就是说,如果代理服务器仍然没有收到来自HTTP Server的响应,我什至不知道客户端已经终止了连接...)

Any help will be appreciated. 任何帮助将不胜感激。

Thanks! 谢谢!

Willy 威利

Indy uses infinite timeouts by default. Indy默认使用无限超时。 To do what you are asking for, you need to set the ReadTimeout property of the outbound connection to the target server. 要执行您要的操作,需要设置与目标服务器的出站连接的ReadTimeout属性。 You can access that connection via the TIdHTTPProxyServerContext.OutboundClient property. 您可以通过TIdHTTPProxyServerContext.OutboundClient属性访问该连接。 Use the OnHTTPBeforeCommand event, which is triggered just before the OutboundClient connects to the target server, eg: 使用OnHTTPBeforeCommand事件,该事件在OutboundClient连接到目标服务器之前触发,例如:

#include "IdTCPClient.hpp"

void __fastcall TForm1::IdHTTPProxyServer1HTTPBeforeCommand(TIdHTTPProxyServerContext *AContext)
{
    static_cast<TIdTCPClient*>(AContext->OutboundClient)->ReadTimeout = ...;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM