Delphi Indy IdHTTPServer(IdHTTPServer) で UTF-8 を返す
Indy の HTTP Server (TIdHttpServer)で、UTF-8 をレスポンスさせる
- procedure TForm1.IdHTTPServer1CommandGet(AContext: TIdContext; ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
- var S: string;
- begin
- S := '<html><head></head><body>Hello World!ハローワールド!</body></html>';
- // UTF-8
- AResponseInfo.ContentStream := TStringStream.Create(S, TEncoding.UTF8);
- AResponseInfo.ContentType := 'text/html; charset=utf-8';
- {
- // Shift-JIS
- AResponseInfo.ContentStream := TStringStream.Create(S, TEncoding.GetEncoding(932));
- AResponseInfo.ContentType := 'text/html; charset=shift-jis';
- }
- end;
charset の記述がないと、ブラウザは正しくエンコードを判断してくれない
コメント