delphi - 是否可以在 TIdHTTPServer onCommandGet 事件中使用 TIdHTTP(客户端)重定向请求并返回响应?

标签 delphi httpclient indy httpserver

我想知道是否可以使用 onCommandGet 事件将客户端请求重定向到另一个主机/端口,使用 TIdHTTP(客户端)获取我需要的信息并通过 AResponseInfo 将其发送回客户端?

它应该看起来像这样:

procedure HTTPServerCommandGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
var
client : TIdHTTP;
begin
  client := TIdHTTP.Create();
  try
    client.Request := ARequestInfo; // or somehow put the ARequestInfo in the client
    ... // in here I don't know how to make the GET, POST, HEAD or other 
    ... // (if possible) request to 'some_host:some_port'
    AResponseInfo := client.Response; // or somehow put the client Response in AResponseInfo
  finally
    FreeAndNil(client);
  end;


end;

最佳答案

没有本地解决方案可以满足您的要求。您必须手动实现它。根据需要将 ARequestInfo 属性中的相关值复制到 TIdHTTP.Request 中,然后调用 TIdHTTP.Get()TIdHTTP.Post( )等,然后根据需要将TIdHTTP.Response中的相关值复制到AResponseInfo中。

关于delphi - 是否可以在 TIdHTTPServer onCommandGet 事件中使用 TIdHTTP(客户端)重定向请求并返回响应?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23293113/

相关文章:

delphi - idhttp indy post,使用 utf-8 做请求(参数)

delphi - Firemonkey 应用程序的单元测试

delphi - 如何在指针的双链表上实现快速排序?

javascript - 如何检查数据是否完整加载以使用异步管道Angular 8

android - java.lang.NullPointerException : lock == null while get json file from server 异常

Android:oauth.signpost.exception.OAuthCommunicationException:与服务提供商的通信失败:没有对等证书

Delphi Indy ReadLn 超时

delphi - 使用 SSL 连接时出错

delphi - 如何更改 Delphi 应用程序中数字键的小数分隔符?

delphi - 将 Indy 10 IdHTTP 与 TLS 1.2 结合使用