Inno安装脚本中的HTTP POST请求 [英] HTTP POST request in Inno Setup Script

查看:870
本文介绍了Inno安装脚本中的HTTP POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to submit some information collected from user during Inno setup installation to our server via POST.

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

Obvious solution would be to include an .exe file that the setup would extract into temporary location and launch with parameters. However, I'm wondering - is there is any easier/better way?

推荐答案

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

Based on jsobo advice of using WinHttp library, I came with this very simple code that does the trick. Say, you want to send serial number for verification just before the actual installation starts. In the code section, put:

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

The Open method takes as arguments the HTTP method, the URL and whether to do async request and it seems like we need to add SetRequestHeader in order to set the Content-Type header to application/x-www-form-urlencoded.

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

WinHttpReq.Status will hold the response code, so to check if the server returned successfully:

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的所有方法和属性 object。

http://msdn.microsoft.com/en-us/library/aa384106.aspx lists all methods and properties of the WinHttpRequest object.

另外,为了避免运行时错误(如果主机无法访问可能会发生),最好用<$包围代码c $ c>尝试/除代码。

Also, to avoid run-time errors (can happen if the host is unreachable) it is a good idea to surround the code with try/except code.

这篇关于Inno安装脚本中的HTTP POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆