TsgcWebSocketHTTPServer › Olaylar › OnCommandGet
HTTP sunucusu bir GET, POST veya HEAD isteği aldığında tetiklenir, böylece uygulama yanıtı oluşturabilir.
property OnCommandGet: TIdHTTPCommandEvent;
// TIdHTTPCommandEvent = procedure(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo) of object
—
OnCommandGet, bileşen tarafından sunulan HTTP trafiği (GET, POST ve HEAD) için ana giriş noktasıdır. ARequestInfo isteği sunar (Document, Params, AuthUsername, Headers, PostStream, RemoteIP...) ve AResponseInfo giden yanıttır: gövde için ContentText veya ContentStream, MIME türü için ContentType ve HTTP durum kodu için ResponseNo (200, 404...) değerlerini ayarlayın; diskten bir dosya göndermek için AResponseInfo.ServeFile çağırın. İşleyiciler bağlantı iş parçacığı bağlamında çalışır, bu nedenle doğrudan UI erişiminden kaçının veya senkronize bir dağıtıma geçin. DocumentRoot altında zaten bulunan dosyalara yönelik istekler otomatik olarak sunulur ve bu olayı tetiklemez.
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;