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.

 


void OnHTTPRequest(TsgcWSConnection_HTTPAPI aConnection,
	THttpServerRequest aRequestInfo,
	ref THttpServerResponse aResponseInfo)
{
  if (aRequestInfo.Method == "GET")
  {
    if (aRequestInfo.Document == "/test.html")
	{
	  aResponseInfo.ResponseNo = 200;
	  aResponseInfo.ContentText = "OK";
	  aResponseInfo.ContentType = "text/html; charset=UTF-8";
	}
	else
	{
	  aResponseInfo.ResponseNo = 404;
	}
  }
  else
  {  
    aResponseInfo.ResponseNo = 500;
  }
}