2012-07-23 39 views
1

將請求轉發到另一臺代理服務器當前我想讓我的indy代理服務器將請求轉發到另一臺代理服務器。我找到了this link,並自己試了一下。但是,如果沒有任何錯誤信息,我的代碼就無法工作,就好像我沒有做任何改變。我的代碼如下面的C++ XE2。如何使用TIdHTTPProxyServer(代理鏈)

void __fastcall TForm3::MyProxyHTTPBeforeCommand(TIdHTTPProxyServerContext *AContext) 
{ 
    TIdIOHandlerStack* tempIO = new TIdIOHandlerStack(NULL); 

    TIdConnectThroughHttpProxy* tempProxy = new TIdConnectThroughHttpProxy(NULL); 
    tempProxy->Enabled = true; 
    tempProxy->Host = "localhost"; 
    tempProxy->Port = 8181 ; 
    tempIO->TransparentProxy = tempProxy; 
    AContext->OutboundClient->IOHandler = tempIO; 

} 

回答

2

最後我發現我做了一些愚蠢的事情。正確的代碼應該如下...

void __fastcall TForm3::MyProxyHTTPBeforeCommand(TIdHTTPProxyServerContext *AContext) 
{ 
    TIdIOHandlerStack* tempIO = new TIdIOHandlerStack(AContext->OutboundClient); 

    TIdConnectThroughHttpProxy* tempProxy = new TIdConnectThroughHttpProxy(AContext->OutboundClient); 
    tempProxy->Enabled = true; 
    tempProxy->Host = "localhost"; 
    tempProxy->Port = 8181 ; 
    tempIO->TransparentProxy = tempProxy; 
    AContext->OutboundClient->IOHandler = tempIO;