TsgcWebSocketServer_HTTPAPI | Invio di una risposta di testo

Utilizzi l'evento OnHTTPRequest per gestire le richieste HTTP.

 

La classe THttpServerRequest contiene i dati della richiesta HTTP.

 

 

La classe THttpServerResponse contiene i dati della risposta HTTP.

 

 

Esempio: se il server riceve una richiesta GET per il documento "/test.html", invia una risposta OK; altrimenti invia un 404 se si tratta di una richiesta GET per un altro documento, o un errore 500 se si tratta di un metodo diverso.

 


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;