TsgcWebSocketServer_HTTPAPI | Send Text Response

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

 

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

 

 

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

 

 

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

 


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;