Make a HTTP GET or POST Request with InnoSetup

Posted on September 12, 2020 at 11:34 am

You can use WinHttpRequest class:

*** To avoid run-time errors surround the code with try/except ***

To make a HTTP GET request with InnoSetup use this:

var
  WinHttpReq: Variant;
begin
  WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
  WinHttpReq.Open('GET', 'https://www.example.com/', False);
  WinHttpReq.Send('');
  if WinHttpReq.Status <> 200 then
  begin
    Log('HTTP Error: ' + IntToStr(WinHttpReq.Status) + ' ' + WinHttpReq.StatusText);
  end
    else
  begin
    Log('HTTP Response: ' + WinHttpReq.ResponseText);
  end;
end;

To make a HTTP POST request with InnoSetup use this:

var
  WinHttpReq: Variant;
begin
  WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
  WinHttpReq.Open('POST', 'https://www.example.com/', False);
  WinHttpReq.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
  WinHttpReq.Send('POST_DATA_HERE');
  if WinHttpReq.Status <> 200 then
  begin
    Log('HTTP Error: ' + IntToStr(WinHttpReq.Status) + ' ' + WinHttpReq.StatusText);
  end
    else
  begin
    Log('HTTP Response: ' + WinHttpReq.ResponseText);
  end;
end;

To change the default timeouts use SetTimeouts():

WinHttpReq.SetTimeouts(5000, 5000, 5000, 5000);

References:

https://stackoverflow.com/a/42806460

Receive updates via email

Other Posts

Updated Posts