Why send HTTP request doesn't work?

倾然丶 夕夏残阳落幕 提交于 2020-01-17 02:58:06

问题


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.



来源:https://stackoverflow.com/questions/25266692/why-send-http-request-doesnt-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!