TsgcWebSocketHTTPServer | 无响应正文的 404 错误

默认情况下,如果没有分配 ContentText 或 ContentStream,Indy 库会为 HTTP 响应添加内容体。如果您希望返回空响应体(例如 404 错误),可以使用以下方法。

 

创建一个不含内容的新 TStringStream,并将其赋值给 HTTP 响应的 ContentStream 属性。这样,HTTP 响应将在不包含默认 HTML 标签的情况下发送。

 

示例

 


procedure OnCommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; 
  AResponseInfo: TIdHTTPResponseInfo);
begin
  AResponseInfo.ContentStream := TStringStream.Create('');
  AResponseInfo.ContentType := 'text/html';
  AResponseInfo.ResponseNo := 404;
end;