Delphi w Indy 10:idHTTPRequest POST总是HTTP 1.0,如何使它成为HTTP 1.1?

Jon*_*ica 6 delphi indy

我们正在向Web服务发出POST请求.

工作良好.

但是,我们注意到请求始终是HTTP 1.0,这导致我们的Web服务器拒绝gzip响应.

如果请求是HTTP 1.1,则响应被gzip压缩.

我们如何正确地要求Indy 10发出HTTP 1.1 POST请求?

谢谢!

TLa*_*ama 11

hoKeepOrigProtocol选项包含在HTTPOptions属性集中(将其设置为True).除了将ProtocolVersion属性设置为pv1_1(这是默认值).

TIdCustomHTTP.Post方法代码中有一个解释当前行为的注释:

目前,在发布POST时,IdHTTP将自动将协议设置为版本1.0,与其最初的值无关. 这是因为有些服务器完全不尊重RFC.特别是,他们不尊重发送/不发送Expect:100-Continue标头.在我们找到不破坏RFC的最佳解决方案之前,我们将POSTS限制为1.0版.

以下几行是对版本1.0的更改,其中包含以下注释:

// If hoKeepOrigProtocol is SET, it is possible to assume that the developer
// is sure in operations of the server
if not (hoKeepOrigProtocol in FOptions) then begin
  if Connected then begin
    Disconnect;
  end;
  FProtocolVersion := pv1_0;
end;
Run Code Online (Sandbox Code Playgroud)

如果您有hoKeepOrigProtocol选项,则跳过上面的代码(版本不会更改)HTTPOptions.