Why send HTTP request doesn't work?

2019-08-22 01:44发布

问题:

I've implemented the code below to send HTTP request to a server but for some reason it's not working (no entry on fiddler) can someone help ? [Edit] I've added Error handling to the code

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

[Setup]
...

[Files]
Source: "MyProg.exe"; DestDir: "{app}"; Flags: ignoreversion

; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Icons]
Name: "{group}\My Program"; Filename: "{app}\MyProg.exe"
Name: "{commondesktop}\My Program"; Filename: "{app}\MyProg.exe"; Tasks: desktopicon

[Run]
Filename: "{app}\MyProg.exe"; Description: "{cm:LaunchProgram,My Program}"; Flags: nowait postinstall skipifsilent


[code]

procedure CurStepChanged(CurStep: TSetupStep);
var
  WinHttpReq: Variant;
begin
  if CurStep = ssDone then
      begin

      WinHttpReq := CreateOleObject('WinHttp.WinHttpRequest.5.1');
      WinHttpReq.Open('GET', 'http://publishers-x.databssint.com/', false);
      WinHttpReq.SetRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
      WinHttpReq.Send('cool');
      // WinHttpReq.ResponseText will hold the server response
          if WinHttpReq.Status <> 200 then
begin
  MsgBox(WinHttpReq.Status, mbError, MB_OK);
end
else
begin
  MsgBox('SUCCESS', mbInformation, MB_OK);
end;


    end;
  end;

回答1:

Any 2xx status code is successful. In your case, 202 means "accepted". It's deliberately vague, but the request did get through to a server which replied.

As for why it's not showing in Fiddler, Fiddler is at the application level, and acts as a proxy rather than a packet monitor. The WinHttpRequest documentation implies that it does NOT use the normal system configured proxy, but instead makes use of its own configuration, or values set at run time.

If you want to test with Fiddler, call SetProxy with Fiddler's details:

WinHttpReq.SetProxy(2, 'localhost:888');

Alternatively, use WireShark to monitor the network traffic directly.



标签: inno-setup