我想在Inno安装程序安装期间通过POST将一些从用户收集的信息提交到我们的服务器.
解决方法
基于jsobo使用WinHttp库的建议,我带着这个非常简单的代码来实现这个窍门.假设您要在实际安装开始之前发送序列号进行验证.在代码部分,放:
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对象的所有方法和属性.