【问题标题】:Redirect HTTP to HTTPS TWebModule Delphi将 HTTP 重定向到 HTTPS TWebModule Delphi
【发布时间】:2020-04-17 20:48:05
【问题描述】:

我有 Delphi Web 服务,使用 TWebModule.. 但是,我对 HTTP/HTPPS 有疑问。 我无法将请求 http 重定向到 https。

你能帮帮我吗?

【问题讨论】:

    标签: delphi delphi-xe8


    【解决方案1】:

    这很容易。在 WebModuleUnit 中键入以下内容:

    procedure TWebModule1.WebModule1DefaultHandlerAction(Sender: TObject;
        Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
    begin
      if Request.QueryFields.Values['proto'] = 'http' then
        if Request.QueryFields.Values['target'] <> '' then
          Response.SendRedirect('https://' + Request.QueryFields.Values['target'])
        else
          Response.Content := '<HTML><BODY>Invalid URI</BODY></HTML>';
      Response.Content :=
        '<html>' +
        '<head><title>DataSnap Server</title></head>' +
        '<body>DataSnap Server</body>' +
        '</html>';
    end;
    

    【讨论】:

      猜你喜欢
      • 2017-11-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-24
      • 2013-11-05
      • 2012-11-02
      • 2011-03-29
      相关资源
      最近更新 更多