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

前端之家收集整理的这篇文章主要介绍了Delphi w Indy 10:idHTTPRequest POST总是HTTP 1.0,如何使它成为HTTP 1.1?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我们正在向Web服务发出POST请求.

工作良好.

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

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

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

谢谢!

解决方法

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

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

Currently when issuing a POST,IdHTTP will automatically set the
protocol to version 1.0 independently of the value it had initially.

This is because there are some servers that don’t respect the RFC to
the full extent. In particular,they don’t respect sending/not sending
the Expect: 100-Continue header. Until we find an optimum solution
that does NOT break the RFC,we will restrict POSTS to version 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;

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

原文链接:https://www.f2er.com/delphi/239291.html

猜你在找的Delphi相关文章