c++ - How to redirect Post requests using TIdHTTPProxyServer -
currently want redirect specific post requests using indy10 tidhttpproxyserver. followed page
http://embarcadero.newsgroups.archived.at/public.delphi.internet.winsock/200904/0904301714.html
and wrote simple sample follow.
oid __fastcall tform3::myproxyhttpbeforecommand(tidhttpproxyservercontext *acontext) { if (acontext->target == "http://example.com/need_redirect_url" ) { tidiohandler* io = acontext->connection->iohandler; io->writeln("http/1.0 302 moved temporarily"); io->writeln("location: http://exampledomain.com/target_url"); io->writeln("connection: close"); } } it works if press "http://sample.com/need_redirect_url" url bar of browser. return nothing(no matter post or get) if xmlhttprequest targeted same url.
i have admit unfamiliar how http works. , wonder if there better way want.
although using c++builder xe2. delphi samples appreciated there less examples using indy components using c++
your code not writing blank line terminates http headers sending. need throw exception prevent tidhttpproxyserver navigating client's requested url after onbeforecommand event handler exits.
try this:
void __fastcall tform3::myproxyhttpbeforecommand(tidhttpproxyservercontext *acontext) { if (acontext->target == "http://xxx.com/need_redirect_url" ) { tidiohandler* io = acontext->connection->iohandler; io->writeln("http/1.0 302 moved temporarily"); io->writeln("location: http://mydomain.com/target_url"); io->writeln("connection: close"); io->writeln(""); abort(); } }
Comments
Post a Comment