OnCommandGet을 사용하여 HTTP 클라이언트 요청을 처리하십시오. 다음 매개변수를 사용하십시오:
procedure OnCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo;
AResponseInfo: TIdHTTPResponseInfo);
begin
if ARequestInfo.Document = '/' then
begin
AResponseInfo.ContentText := '<html><head><title>Test Page</title></head><body></body></html>';
AResponseInfo.ContentType := 'text/html';
AResponseInfo.ResponseNo := 200;
end;
end;
이 이벤트를 사용하여 HTTP 응답을 사용자 지정하십시오. 예를 들어, 일부 엔드포인트는 권한 부여 체계를 사용하고 다른 엔드포인트는 권한 부여 없이 액세스할 수 있도록 하려면 options 매개변수를 사용하여 허용하거나 비활성화하십시오. 아래는 Authorization Basic이 활성화되어 있지만 사용자가 /public 엔드포인트를 요청할 때 권한 부여가 필요하지 않은 예입니다.
procedure OnBeforeCommand(const aConnection: TsgcWSConnection; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo; var aOptions: TsgcHTTPCommandOptions);
begin
if aRequestInfo.Document = '/public' then
aOptions := [hcoAuthorizedBasic];
end;