[英]Indy HTTP server on Linux returns only last character of response text
环境:Ubuntu 12.04 LTS,Indy 10.5.9 rev 4885,Lazarus 1.0.4 / FPC 2.6.0。
使用我简单的TIdHTTPServer测试程序,Web浏览器仅显示最后一个字符('!'),而不显示完整的响应,后者应为'Hello world!'。
我可以看到在函数ToBytes
( ToBytes
6059行)中,传递的AValue参数中的文本仍然正确,ASrcEncoding是TIdASCIIEncoding,ADestEncoding是“ ISO-8559-1”。 在执行6061行之后(LBytes:= TIdTextEncoding.Convert(ASrcEncoding,ADestEncoding,LBytes);),LBytes数组包含#33,后跟零。
我的示例项目:
program MyHTTPServer;
uses
cthreads,
IdHTTPServer, IdCustomHTTPServer, IdContext, IdSocketHandle, IdGlobal,
SysUtils;
type
TMyServer = class (TIdHTTPServer)
public
procedure InitComponent; override;
procedure OnGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
end;
procedure Demo;
var
Server: TMyServer;
begin
Server := TMyServer.Create(nil);
try
Server.Active := True;
WriteLn('Hit any key to terminate.');
ReadLn;
finally
Server.Free;
end;
end;
procedure TMyServer.InitComponent;
var
Binding: TIdSocketHandle;
begin
inherited;
OnCommandGet := OnGet;
Bindings.Clear;
Binding := Bindings.Add;
Binding.IP := '127.0.0.1';
Binding.Port := 8080;
Binding.IPVersion := Id_IPv4;
end;
procedure TMyServer.OnGet(AContext: TIdContext;
ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
AResponseInfo.ContentText := 'Hello world!';
end;
begin
IdGlobal.GIdIconvUseTransliteration := True;
Demo;
end.
该问题已在SVN干线版本4889中修复。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.