【发布时间】:2012-06-05 07:17:17
【问题描述】:
目前我想使用 Indy10 TIdHTTPProxyServer 重定向特定的 Post 请求。我关注了页面
http://embarcadero.newsgroups.archived.at/public.delphi.internet.winsock/200904/0904301714.html
并写了一个简单的示例如下。
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");
}
}
如果我将“http://sample.com/need_redirect_url”按到浏览器的 URL 栏中,它会起作用。 但是,如果它是针对同一 URL 的 XMLHttpRequest,则不返回任何内容(无论是 Post 还是 Get)。
我不得不承认我真的不熟悉 HTTP 的工作原理。而且我也想知道是否有更好的方法来做我想做的事。
虽然我使用的是 C++Builder XE2。 Delphi 示例也受到赞赏,因为使用 C++ 使用 indy 组件的示例较少
【问题讨论】:
标签: c++ delphi indy10 c++builder-xe2