Asynchronous HTTP POST request without waiting for a response in Inno Setup

I have an Inno Setup installer and you need to call an API call during installation. This sends some data to the remote API.

A POST call is made in the [Code] section using Pascal and an object WinHttpRequest. The API is ASP.Net WebAPI 2 (C #).

I have full control over all parts of the process, i.e. the Inno Setup script, its code section and WebAPI.

Problem

I can make a POST call synchronously without any problems, but if I set the async flag truein a method WinHttpRequest.Open(), the method .Send()does not work at all.


procedure PostData(postural: String);
   var 
     WinHttpReq: Variant;
     ReqContent: String;
   begin
     try
       WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
       ReqContent := 'item=value';
       WinHttpReq.Open('POST', postUrl, true);
       WinHttpReq.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
       WinHttpReq.Send(ReqContent);
     except
     end;
   end;

I checked with a breakpoint in the VisualStudio debugger, and the endpoint is never called.

Google , . , API- Fire-and-forget.


API ?

.

+4
1

WinHttpRequest "".

, :

  • WinHttpReq . PostData . WinHttpReq ( PostData).

    var 
      WinHttpReq: Variant;
    
    procedure PostData(postural: String);
    var 
      ReqContent: String;
    begin
      try
        WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
        ReqContent := 'item=value';
        WinHttpReq.Open('POST', postUrl, true);
        WinHttpReq.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
        WinHttpReq.Send(ReqContent);
      except
      end;
    end;
    
  • () , .

+3

Source: https://habr.com/ru/post/1679244/


All Articles