mormot支持https
mormot支持https
将ssl证书导入电脑系统,以Windows 10为例:
运行 mmc
证书导入成功后,双击证书,查看证书指纹:
第二项工作:将证书与https绑定:
以管理员身份启动cmd,输入下列命令:
netsh http add sslcert ipport=0.0.0.0:443 certhash=3a0a8fa7cbcab141e102eaab457b1299af8f82cc appid={FDC3C336-D4AF-4EA8-BAA2-15536FDE8799}
第三项工作:修改Delphi源程序:
- program HttpApiServer;
- {$APPTYPE CONSOLE}
- {$I Synopse.inc}
- //['{FDC3C336-D4AF-4EA8-BAA2-15536FDE8799}']
- //netsh http add sslcert ipport=0.0.0.0:443 certhash=3a0a8fa7cbcab141e102eaab457b1299af8f82cc appid={FDC3C336-D4AF-4EA8-BAA2-15536FDE8799}
- //netsh http delete sslcert ipport=0.0.0.0:443
- uses
- {$I SynDprUses.inc} // use FastMM4 on older Delphi, or set FPC threads
- SysUtils,
- SynCommons,
- SynZip,
- SynCrtSock;
- type
- TTestServer = class
- protected
- fPath: TFileName;
- fPort, fRoot: string;
- fServer: THttpApiServer;
- fHttps: Boolean;
- function Process(Ctxt: THttpServerRequest): cardinal;
- function ShowDirectory(Ctxt: THttpServerRequest;
- const FileName: TFileName; FN: RawUTF8): cardinal;
- public
- constructor Create(const Path: TFileName);
- destructor Destroy; override;
- end;
- { TTestServer }
- constructor TTestServer.Create(const Path: TFileName);
- begin
- fPath := IncludeTrailingPathDelimiter(Path);
- fPort := '443';
- fRoot := '/test';
- fHttps := True;
- fServer := THttpApiServer.Create(false);
- fServer.AddUrl(fRoot, fPort, fHttps, '+', true);
- fServer.RegisterCompress(CompressDeflate); // our server will deflate html :)
- fServer.OnRequest := Process;
- fServer.Clone(31); // will use a thread pool of 32 threads in total
- end;
- destructor TTestServer.Destroy;
- begin
- fServer.RemoveUrl(fRoot, fPort, fHttps, '+');
- fServer.Free;
- inherited;
- end;
- {$WARN SYMBOL_PLATFORM OFF}
- function TTestServer.Process(Ctxt: THttpServerRequest): cardinal;
- var
- FileName: TFileName;
- FN: RawUTF8;
- begin
- write(Ctxt.Method, ' ', Ctxt.URL);
- if not IdemPChar(pointer(Ctxt.URL), PAnsiChar(UpperCase(fRoot))) then begin
- WriteLn(' End with 404');
- result := 404;
- exit;
- end;
- FN := StringReplaceChars(UrlDecode(copy(Ctxt.URL, Length(fRoot) + 1, maxInt)),
- '/', '\');
- if PosEx('..', FN) > 0 then begin
- WriteLn(' .. End with 404');
- result := 404; // circumvent obvious potential security leak
- exit;
- end;
- while (FN <> '') and (FN[1] = '\') do
- delete(FN, 1, 1);
- while (FN <> '') and (FN[length(FN)] = '\') do
- delete(FN, length(FN), 1);
- FileName := fPath + UTF8ToString(FN);
- writeLn(' => ' + FileName); //c5soft
- if DirectoryExists(FileName) then begin
- Result := ShowDirectory(ctxt, FileName, FN);
- end else begin
- // http.sys will send the specified file from kernel mode
- Ctxt.OutContent := StringToUTF8(FileName);
- Ctxt.OutContentType := HTTP_RESP_STATICFILE;
- result := 200; // THttpApiServer.Execute will return 404 if not found
- end;
- end;
- var
- Msg: string;
- function TTestServer.ShowDirectory(Ctxt: THttpServerRequest;
- const FileName: TFileName; FN: RawUTF8): cardinal;
- var
- W: TTextWriter;
- SRName, href: RawUTF8;
- i: integer;
- SR: TSearchRec;
- cRoot: string;
- procedure hrefCompute;
- begin
- SRName := StringToUTF8(SR.Name);
- href := FN + StringReplaceChars(SRName, '\', '/');
- end;
- begin
- if fRoot <> '/' then cRoot := fRoot + '/' else cRoot := fRoot;
- // reply directory listing as html
- W := TTextWriter.CreateOwnedStream;
- try
- W.Add('<html><body style="font-family: Arial">' +
- '<h3>%</h3><p><table>', [FN]);
- FN := StringReplaceChars(FN, '\', '/');
- if FN <> '' then
- FN := FN + '/';
- if FindFirst(FileName + '\*.*', faDirectory, SR) = 0 then begin
- repeat
- if (SR.Attr and faDirectory <> 0) and (SR.Name <> '.') then begin
- hrefCompute;
- if SRName = '..' then begin
- i := length(FN);
- while (i > 0) and (FN[i] = '/') do dec(i);
- while (i > 0) and (FN[i] <> '/') do dec(i);
- href := copy(FN, 1, i);
- end;
- W.Add('<tr><td><b><a href="' + cRoot + '%">[%]</a></b></td></tr>', [href,
- SRName]);
- end;
- until FindNext(SR) <> 0;
- FindClose(SR);
- end;
- if FindFirst(FileName + '\*.*', faAnyFile - faDirectory - faHidden, SR) = 0 then begin
- repeat
- hrefCompute;
- if SR.Attr and faDirectory = 0 then
- W.Add('<tr><td><b><a href="' + cRoot +
- '%">%</a></b></td><td>%</td><td>%</td></td></tr>',
- [href, SRName, KB(SR.Size), DateTimeToStr(
- {$IFDEF ISDELPHIXE2}SR.TimeStamp{$ELSE}FileDateToDateTime(SR.Time){$ENDIF})]);
- until FindNext(SR) <> 0;
- FindClose(SR);
- end;
- W.AddShort('</table></p><p><i>Powered by mORMot''s <strong>');
- W.AddClassName(Ctxt.Server.ClassType);
- W.AddShort('</strong></i> - ' +
- 'see <a href=https://synopse.info>https://synopse.info</a></p></body></html>');
- Ctxt.OutContent := W.Text;
- Ctxt.OutContentType := HTML_CONTENT_TYPE;
- result := 200;
- finally
- W.Free;
- end;
- end;
- begin
- with TTestServer.Create('D:\Programs\Nginx\wwwroot\') do try
- Msg := 'Server is now running on http';
- if fHttps then Msg := Msg + 's';
- msg := msg + '://localhost';
- if fPort <> '80' then
- Msg := Msg + ':' + fPort;
- Msg := Msg + fRoot + #13#10#13#10'Press [Enter] to quit';
- WriteLn(Msg);
- readln;
- finally
- Free;
- end;
- end.
mormot支持https的更多相关文章
- node如何让一个端口同时支持https与http
众所周知node是一个高性能的web服务器,使用它可以很简单的创建一个http或https的服务器. 比如一个很简单的http服务器: var http = require('http'); var ...
- 如何让你的网站支持https
如何让你的网站支持https 当今世界的主流网站基本都是使用https对外界提供服务,甚至有某些公司建议完全使用https, 那么https是什么呢?请参考如下的图解,https是在我们通常说的tcp ...
- 让你的网站免费支持 HTTPS 及 Nginx 平滑升级
为什么要使用 HTTPS ? 首先来说一下 HTTP 与 HTTPS 协议的区别吧,他们的根本区别就是 HTTPS 在 HTTP 协议的基础上加入了 SSL 层,在传输层对网络连接进行加密.简单点说在 ...
- 在iOS APP中使用H5显示百度地图时如何支持HTTPS?
现象: 公司正在开发一个iOSAPP,使用h5显示百度地图,但是发现同样的H5页面,在安卓可以显示出来,在iOS中就显示不出来. 原因分析: 但是现在iOS开发中,苹果已经要求在APP中的所有对外连接 ...
- iOS支持Https
http://oncenote.com/2014/10/21/Security-1-HTTPS/?hmsr=toutiao.io&utm_medium=toutiao.io&utm_s ...
- 【转】如何在Windows+VS2005使用最新静态libcurl 7.35.0获取网页数据,支持HTTPS
地址: http://blog.csdn.net/hujkay作者:Jekkay Hu(34538980@qq.com)关键词:Windows,curl,ssl, visual c++ 2005, ...
- Web API应用支持HTTPS的经验总结
在我前面介绍的WebAPI文章里面,介绍了WebAPI的架构设计方面的内容,其中提出了现在流行的WebAPI优先的路线,这种也是我们开发多应用(APP.微信.微网站.商城.以及Winform等方面的整 ...
- loadrunner支持https协议的操作方法-经验总结
问题:用户portal支持https协议,用loadrunner录制登陆脚本时发现未录制到用户名和密码 录制到的脚本如下: login() { lr_think_time(10); web_url(& ...
- php中curl不支持https的解决办法
在php程序中使用curl去访问https站点时,报错:Protocol https not supported or disabled in libcurl 该错误信息表示php当时编译时使用的cu ...
随机推荐
- C# 将某个方法去异步执行
C# 将某个方法去异步执行 Task.Run(() => { string msgerror = SendPhoneCode.NewSendByTemplate(apply.PhoneNum, ...
- ASP.NET MVC3 Model的常用验证示例
1.金额(10位整数,2位小数) #region 余额 /// <summary> /// 余额 /// </summary> [DisplayName("余额&qu ...
- 2018-11-3& maven
https://www.cnblogs.com/clsn/p/7944116.html#auto_id_10 http://www.runoob.com/maven/maven-creating-pr ...
- 解决方案:centos运行shell脚本时报“$'\r': 未找到命令”
=============================================== 2018/9/12_第1次修改 ccb_warlock == ...
- python3 pandas DataFrame常见用法
df = pandas.read_clipboard() df 获取索引和值 df.index df.values DataFrame的values属性将数据以二维ndarray形式返回,dtype类 ...
- css1-puchong1
HTML DOM (文档对象模型) 当网页被加载时,浏览器会创建页面的文档对象模型(Document Object Model). HTML DOM 模型被构造为对象的树. 一:HTML DOM 树 ...
- excel 2016 for mac破解
1: 首先去官网下载一个正版的: 2:再下载一个破解工具: 链接: http://pan.baidu.com/s/1i4AFHFf 密码: 3yf8 3:最后按照破解教程破解: http://jing ...
- MySQL 中国省市区SQL表数据
MySQL 中国省市区SQL表数据 1.查省SELECT * FROM china WHERE china.Pid=02.查市SELECT * FROM chinaWHERE china.Pid= ...
- UVa140 Bandwidth 小剪枝+双射小技巧+枚举全排列+字符串的小处理
给出一个图,找出其中的最小带宽的排列.具体要求见传送门:UVa140 这题有些小技巧可以简化代码的编写. 本题的实现参考了刘汝佳老师的源码,的确给了我许多启发,感谢刘老师. 思路: 建立双射关系:从字 ...
- MyBatis 从浅入深 随笔整理
MyBatis? archetypeCatalog = internal 本文档单独出现的_parameter都标识为变量名 一.三个基本要素: 核心接口和类 MyBatis 核心配置文件 SQL映射 ...