TsgcWebSocketServer_HTTPAPI | Send Text Response

Use the event OnHTTPRequest to handle the HTTP Requests. 

 

The class THttpServerRequest contains the HTTP Request Data.

 

 

The class THttpServerResponse contains the HTTP response Data.

 

 

Example: if the server receives a GET request to the document "/test.html" send a OK response, otherwise send a 404 if it's a GET request or error 500 if it's another method.

 


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;