Inno安装脚本中的HTTP POST请求

时间:2011-02-02 07:43:12

标签: http inno-setup http-post

我想通过POST将Inno安装过程中从用户收集的一些信息提交给我们的服务器。

明显的解决方案是包含一个.exe文件,该文件将安装程序提取到临时位置并使用参数启动。但是,我想知道 - 有更简单/更好的方法吗?

3 个答案:

答案 0 :(得分:19)

基于使用WinHttp库的jsobo建议,我附带了这个非常简单的代码,可以解决这个问题。比如,您希望在实际安装开始之前发送序列号以进行验证。在代码部分中,输入:

procedure CurStepChanged(CurStep: TSetupStep);
var
  WinHttpReq: Variant;
begin
  if CurStep = ssInstall then
  begin
    if AutoCheckRadioButton.Checked = True then
    begin
      WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
      WinHttpReq.Open('POST', '<your_web_server>', false);
      WinHttpReq.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      WinHttpReq.Send('<your_data>');
      // WinHttpReq.ResponseText will hold the server response
    end;
  end;
end;

Open方法将HTTP方法,URL以及是否执行异步请求作为参数,似乎我们需要添加SetRequestHeader以便将Content-Type标头设置为application/x-www-form-urlencoded

WinHttpReq.Status将保留响应代码,以便检查服务器是否成功返回:

if WinHttpReq.Status <> 200 then
begin
  MsgBox('ERROR', mbError, MB_OK);
end
else
begin
  MsgBox('SUCCESS', mbInformation, MB_OK);
end;

http://msdn.microsoft.com/en-us/library/aa384106.aspx列出了WinHttpRequest对象的所有方法和属性。

此外,为避免运行时错误(如果主机无法访问,可能会发生错误),最好使用try/except代码包围代码。

答案 1 :(得分:3)

您可以随时使用安装程序curl  制作http帖子......

您可以在innosetup中编写一个pascal脚本,以便使用winhttp library

进行通话

或者您可以编写一个vbscript并使用cscript引擎执行该操作,以通过winhttp库执行相同的http调用。

这应该指向至少3个不同的选项来做你需要的。

我认为将exe放在那里是最容易出错的,但是使用带有pascal脚本的winhttp库(由innosetup使用)将是最简单的。

答案 2 :(得分:2)

我没有尝试过,但ISXKB有一个使用HTTP POST的卸载调查条目: http://www.vincenzo.net/isxkb/index.php?title=Uninstall_Survey

相关问题