Inno setup 尝试并排除inno设置中的bug
在我的代码中,我希望发送http请求并在fiddler-Inno setup 尝试并排除inno设置中的bug,inno-setup,Inno Setup,在我的代码中,我希望发送http请求并在fiddler-WinHttpReq.SetProxy(2,'127.0.0.1:8888')中呈现它如果fiddle启动 如果fiddler倒下了,请将其发送给fiddler,我尝试了try [Setup] AppName=Test AppVersion=1.5 DefaultDirName={pf}\test [Code] var WinHttpReq: Variant; function ShowInFiddler(Param: Strin
WinHttpReq.SetProxy(2,'127.0.0.1:8888')中呈现它代码>如果fiddle启动
如果fiddler倒下了,请将其发送给fiddler,我尝试了try
[Setup] AppName=Test AppVersion=1.5 DefaultDirName={pf}\test
[Code]
var
WinHttpReq: Variant;
function ShowInFiddler(Param: String): String;
begin
try
WinHttpReq.SetProxy(2, '127.0.0.1:8888');
except MsgBox('Hello.', mbInformation, MB_OK);
end;
end;
function InitializeSetup(): Boolean;
begin
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
WinHttpReq.Open('GET', 'http://publishers-xxxx.databssint.com/', false);
ShowInFiddler ('');
WinHttpReq.Send(); end;
但是这个例外不起作用,有人能帮忙吗 这不是Inno设置中的错误,因为SetProxy函数不会检查代理是否可用。如果使用错误的参数调用该函数,则该函数将引发异常。
因此,如果您的代理服务器关闭,您应该捕获发送功能的异常,例如,使用默认代理服务器设置
例如:
var
WinHttpReq: Variant;
function InitializeSetup(): Boolean;
begin
WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
WinHttpReq.Open('GET', 'http://publishers-xxxx.databssint.com/', false);
WinHttpReq.SetProxy(2, '127.0.0.1:8888');
try
// first try connecting via given proxy
WinHttpReq.Send();
except
// proxy failed, use default settings
WinHttpReq.SetProxy(0);
try
WinHttpReq.Send();
Result := true;
except
// conncetion failed, handle error here
ShowExceptionMessage();
end;
end;
end;
请记住,默认情况下,调试器将在出现异常时暂停(代理已关闭)。这不会在运行时发生。
希望有帮助。为什么不确保SetProxy
调用仅在测试版本中?这样,您可以在测试中看到它,但您发送的任何版本都不会有不必要的尝试连接到本地代理。这是我们今天所做的,这不是最佳做法,因为理想的做法是QA将批准我们将上载到prod的安装程序,您知道为什么我的try and except
在这里不起作用吗?成功了!10倍“另一个用户”我的QA团队说万岁!