TsgcWebSocketHTTPServer › 이벤트 › OnCommandGet
HTTP 서버가 GET, POST 또는 HEAD 요청을 수신하여 애플리케이션이 응답을 구축할 수 있을 때 발생합니다.
property OnCommandGet: TIdHTTPCommandEvent;
// TIdHTTPCommandEvent = procedure(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo) of object
—
OnCommandGet은 구성 요소가 제공하는 HTTP 트래픽(GET, POST 및 HEAD)의 주 진입점입니다. ARequestInfo는 요청(Document, Params, AuthUsername, Headers, PostStream, RemoteIP 등)을 노출하고 AResponseInfo는 발신 응답입니다. ContentText 또는 ContentStream을 본문으로, ContentType을 MIME 유형으로, ResponseNo를 HTTP 상태 코드(200, 404 등)로 설정하십시오. 디스크의 파일을 디스패치하려면 AResponseInfo.ServeFile을 호출하십시오. 핸들러는 연결 스레드의 컨텍스트에서 실행되므로 직접 UI 액세스를 피하거나 동기화된 디스패치로 전환하십시오. 이미 DocumentRoot 아래에 있는 파일에 대한 요청은 자동으로 제공되며 이 이벤트를 트리거하지 않습니다.
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;