TsgcWebSocketHTTPServer | HTTP-serververzoeken

Gebruik OnCommandGet om HTTP-clientverzoeken te verwerken. Gebruik de volgende parameters:

 

 

 

 


void OnCommandGet(TIdContext *AContext, TIdHTTPRequestInfo *ARequestInfo, 
  TIdHTTPResponseInfo *AResponseInfo)
{
  if (ARequestInfo->Document == "/")
  {
    AResponseInfo->ContentText = "<html><head><title>Test Page</title></head><body></body></html>";
    AResponseInfo->ContentType = "text/html";
    AResponseInfo->ResponseNo = 200;
  }
}

 

OnBeforeCommand

Gebruik deze gebeurtenis om het HTTP-antwoord aan te passen. Als u bijvoorbeeld wilt dat sommige eindpunten een autorisatieschema gebruiken terwijl andere zonder autorisatie toegankelijk zijn, gebruik dan de opties-parameter om dit toe te staan of uit te schakelen. Hieronder is een voorbeeld waarbij Basic autorisatie is ingeschakeld, maar wanneer een gebruiker het eindpunt /public aanvraagt, is autorisatie niet vereist.

 


void __fastcall TForm1::OnBeforeCommand(TsgcWSConnection* aConnection, TIdHTTPRequestInfo* ARequestInfo, TIdHTTPResponseInfo* AResponseInfo, TsgcHTTPCommandOptions &aOptions)
{
    if (ARequestInfo->Document == "/public")
        aOptions << hcoAuthorizedBasic;
}