Search code examples
delphiproxyc++builderindy

How do I forward request to another proxy server using TIdHTTPProxyServer (proxy chain)


currently I want to make my indy proxy server forward the request to another proxy server. I have found this link and made a try by myself. But my code does not work without any error message as if I had made no change. My code is as below in C++ XE2.

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;

}

Solution

  • Finally I found I did something stupid. The correct code should be as follow...

    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;