delphi - 使用 IHTTPSecurity 绕过 Web 浏览器中的自签名证书
问题描述
我已经研究了IHTTPSECURITY
使用 Delphi 实现接口的所有方法TWebBrowser
。我正在尝试通过 https 导航到一个站点。该站点具有自签名证书。我希望避免在浏览器中弹出/出现安全警告。
如果我silent
将浏览器的模式切换为 true,则不再弹出安全对话框,但浏览器会自动选择“否”作为“您要继续”问题的答案吗?
我相信解决这个问题的方法是通过 IHTTPSecurity 接口。我找到了为 EmbeddedWB ( why-doesnt-queryservice-get-call-for-ihttpsecurity-when-using-tembeddedwb ) 实现此功能的代码。我试图为 实现此功能TWebBrowser
,但该onSecurityProblem
功能不会触发。我的代码如下:
unit Unit1;
interface
uses
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.OleCtrls, Vcl.StdCtrls, SHDocVw, ActiveX, Winapi.Urlmon, Winapi.WinInet;
type TWebBrowser = class(SHDocVw.TWebBrowser, IHTTPSecurity, IWindowForBindingUI)
private
function GetWindow(const guidReason: TGUID; out hwnd): HRESULT; stdcall;
function OnSecurityProblem(dwProblem: Cardinal): HRESULT; stdcall;
end;
type
TForm1 = class(TForm)
WebBrowser1: TWebBrowser;
Button1: TButton;
Edit1: TEdit;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses System.NetEncoding;
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
Flags, TargetFrameName, PostData, headers, url:OleVariant;
authenticate:string;
begin
webBrowser1.Navigate('about:blank');
Flags := '1';
TargetFrameName := '';
PostData := '';
Authenticate := TNetEncoding.Base64.Encode('MediaUser:test');
Headers:='Authorization: Basic '+Authenticate;
webBrowser1.Navigate(Edit1.text, flags, TargetFrameName, PostData, headers);
end;
function TWebBrowser.GetWindow(const guidReason: TGUID;
out hwnd): HRESULT;
begin
Result := S_FALSE;
end;
function TWebBrowser.OnSecurityProblem(dwProblem: Cardinal): HRESULT;
begin
if (dwProblem = ERROR_INTERNET_INVALID_CA) or
(dwProblem = ERROR_INTERNET_SEC_CERT_CN_INVALID)
then Result := S_OK
else Result := E_ABORT;
end;
end.
我究竟做错了什么?
作为一个附带问题,当上述应用程序终止时,我得到一个未指定的EoleException
.
解决方案
推荐阅读
- java - javax.transaction-api:1.3 的 javac 断言错误
- php - 使用文件上传Rest发布数据
- java - Eclipse 控制台不打印汉字
- excel - 使用 sheet().Range().Value 在 VBA 中引用列
- r - 在闪亮中重新编码变量
- angularjs - AngularJs 环境变量(API URL)
- docusignapi - 一旦从批量发送中签名,是否可以得到一份一份的文件?
- powerbi - Power BI - 在图表中仅显示 > 0 的值
- java - 来自 mongoDB 的更改事件中的 updateDescription.updatedFields 为空
- java - 来自 Java 库的 C++ 主应用程序代码的 JNI 调用