为什么发送HTTP请求无效? [英] Why send HTTP request doesn't work?

查看:120
本文介绍了为什么发送HTTP请求无效?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了以下代码,以将HTTP请求发送到服务器,但是由于某种原因,它无法正常工作(在提琴手上没有条目),有人可以帮忙吗?我已在代码中添加了错误处理

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 ? 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;

推荐答案

任何2xx状态代码均成功.在您的情况下,202表示已接受" .这是故意含糊不清的,但请求确实到达了要回复的服务器.

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.

关于为何未在Fiddler中显示的原因,Fiddler处于应用程序级别,并且充当代理而不是数据包监视器. WinHttpRequest 文档表示它不使用正常的系统配置的代理,而是使用其自己的配置或在运行时设置的值.

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.

如果要使用Fiddler进行测试,请使用Fiddler的详细信息调用SetProxy:

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

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

或者,使用WireShark直接监视网络流量.

Alternatively, use WireShark to monitor the network traffic directly.

这篇关于为什么发送HTTP请求无效?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆