TsgcWebSocketServer_HTTPAPI | Send Text Response

HTTP İsteklerini işlemek için OnHTTPRequest olayını kullanın.

 

THttpServerRequest sınıfı HTTP İstek Verilerini içerir.

 

 

THttpServerResponse sınıfı HTTP yanıt Verilerini içerir.

 

 

Örnek: sunucu "/test.html" belgesi için bir GET isteği alırsa, bir OK yanıtı gönderin; aksi takdirde başka bir belge için bir GET isteğiyse 404, farklı bir yöntemse 500 hatası gönderin.

 


procedure OnHTTPRequest(aConnection: TsgcWSConnection_HTTPAPI; 
	const aRequestInfo: THttpServerRequest; 
	var aResponseInfo: THttpServerResponse);
begin
  if aRequestInfo.Method = 'GET' then
  begin
    if aRequestInfo.Document = '/test.html' then
	begin
	  aResponseInfo.ResponseNo := 200;
	  aResponseInfo.ContentText := 'OK';
	  aResponseInfo.ContentType := 'text/html; charset=UTF-8';
	end
	else
	  aResponseInfo.ResponseNo := 404;
  end
  else 
    aResponseInfo.ResponseNo := 500;
end;