我想知道是否可以使用 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/