TsgcWebSocketServer_HTTPAPI | 发送文本响应

使用 OnHTTPRequest 事件处理 HTTP 请求。

 

THttpServerRequest 包含 HTTP 请求数据。

 

 

THttpServerResponse 类包含 HTTP 响应数据。

 

 

示例:如果服务器收到文档"/test.html"的 GET 请求,则发送 OK 响应;否则,如果是对其他文档的 GET 请求,则发送 404,如果是不同的方法,则发送错误 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;