AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Zurück Delphi-PRAXiS Programmierung allgemein Netzwerke Delphi TIdHTTPServer umd Umlaute
Thema durchsuchen
Ansicht
Themen-Optionen

TIdHTTPServer umd Umlaute

Ein Thema von Hobbycoder · begonnen am 13. Sep 2019 · letzter Beitrag vom 13. Sep 2019
 
Hobbycoder

Registriert seit: 22. Feb 2017
1.002 Beiträge
 
#1

TIdHTTPServer umd Umlaute

  Alt 13. Sep 2019, 13:01
Für eine kleine Web-App habe ich mir eine Mini-Webserver geschrieben.
Dieser Webserver macht im Grund nichts anderes, als bei Anfrage den Content aus verschiedenen Dateien zu laden, die quasi als Templates vorliegen, bestimmte Textpassagen gegen dynamische Inforamtionsinhalte auszutauschen und zurück zum Cient zu senden.

Das Ganze sie so aus:
Delphi-Quellcode:
const
  HeaderFile = 'header.html';
  Zaehler = 'zaehler.html';

implementation

procedure AddTemplateFile(const Filename: string;
  var DestinationString: string);
var
  f: TextFile;
  s: string;
begin
  if FileExists(ExtractFilePath(FExefile)+Filename) then
  begin
    AssignFile(f, ExtractFilePath(FExefile)+Filename);
    Reset(f);
    try
      while not Eof(f) do
      begin
        Readln(f, s);
        DestinationString:=DestinationString+s;
      end;
    finally
      CloseFile(f);
    end;
  end;
end;

procedure GenerateZaehlerPage(
  var AResponseInfo: TIdHTTPResponseInfo; MaGUID, Username: string);
begin
  s:='';
  AddTemplateFile(HeaderFile, s);
  AddTemplateFile(Zaehler, s);
  s:=StringReplace(s, '==username==', Username, [rfReplaceAll]);
  AResponseInfo.ContentText:=s;
  AResponseInfo.ResponseNo:=200;
end;

procedure idhtpsrvr1CommandGet(AContext: TIdContext;
  ARequestInfo: TIdHTTPRequestInfo; AResponseInfo: TIdHTTPResponseInfo);
begin
  AContext.Connection.IOHandler.DefStringEncoding := IndyTextEncoding_UTF8;
  AResponseInfo.CharSet:='utf-8';
  if (ARequestInfo.Document='/zaehler.php') then
  begin
    GenerateZaehlerPage(AResponseInfo, ARequestInfo.Session.Content.Values['guid'], ARequestInfo.Session.Content.Values['realname']);
    Exit;
  end;
end;
Header.html:
Code:
<!DOCTYPE html>
<html lang="de">
<head>
  <title>Dummy-App</title>
  <meta charset="utf-8">
  <meta name="apple-mobile-web-app-title" content="TNM Personal" />
  <meta name="application-name" content="TMN Personal">
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8; Content-Transfer-Encoding: quoted-printable" />
  <meta name="format-detection" content="telephone=no" />
  <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  <meta name="mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-capable" content="yes" />
  <meta name="apple-mobile-web-app-status-bar-style" content="black" />
  <meta http-equiv="cache-control" content="max-age=0" />
  <meta http-equiv="cache-control" content="no-cache" />
  <meta http-equiv="expires" content="0" />
  <meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
  <meta http-equiv="pragma" content="no-cache" />
  <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
  <script src="https://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.js"></script>
  <link rel="stylesheet" href="http://code.jquery.com/mobile/1.4.5/jquery.mobile-1.4.5.css">
</head>
Zaehler.html:
Code:
<body>
<form data-ajax="false" id="menu" method="post" action="Menu.php"><input type="submit" value="<< Menu" style="width:30%; height: 40px; font-size:10pt;font-weight:60;padding: 0px 0px"></form>
<div data-role="page" id="menu" data-theme="b">
  <div data-role="main" class="ui-content">
  <h1>==username==</h1>
  <h1>Zähler</h1>
 </div>
</div>
</body>
</html>
Ich habe das mal soweit zusammen gekürzt, damit klar wird, wie ich das mache.
Soweit funktioniert auch alles.

Mein Problem sind die Umlaute z.B. im Wort "Zähler". Dieses wird im Browser als "Zähler" dargestellt.
Kann mir da jemand weiterhelfen?

Rufe ich die html-Dateien aus dem Browser auf, so wird "Zähler" korrekt dargestellt. Wird es von IdHttpServer gesendet, dann nicht. Also muss ich vor dem Senden den Content noch irgendwie umwandelt?
Gruß Hobbycoder
Alle sagten: "Das geht nicht.". Dann kam einer, der wusste das nicht, und hat's einfach gemacht.
  Mit Zitat antworten Zitat
 


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 00:29 Uhr.
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz