TsgcWebSocketServer_HTTPAPI | Send Text Response

HTTP 요청을 처리하려면 OnHTTPRequest 이벤트를 사용하십시오.

 

THttpServerRequest 클래스는 HTTP Request 데이터를 포함합니다.

 

 

THttpServerResponse 클래스는 HTTP 응답 데이터를 포함합니다.

 

 

예제: 서버가 "/test.html" 문서에 대한 GET 요청을 받으면 OK 응답을 보내고, 그렇지 않으면 다른 문서에 대한 GET 요청인 경우 404를, 다른 method인 경우 오류 500을 보냅니다.

 


void __fastcall OnHTTPRequest(TsgcWSConnection_HTTPAPI *aConnection,
	const THttpServerRequest *aRequestInfo,
	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;
  }
}