简体   繁体   English

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

[英]Delphi w Indy 10: idHTTPRequest POST always is HTTP 1.0, how to make it HTTP 1.1?

We are doing POST requests to a web service. 我们正在向Web服务发出POST请求。

Works fine. 工作正常。

However, we notice that the requests are always HTTP 1.0, which causes our web server to decline to gzip the responses. 但是,我们注意到请求始终是HTTP 1.0,这导致我们的Web服务器拒绝gzip响应。

If the requests are HTTP 1.1, then the responses are gzipped. 如果请求是HTTP 1.1,则响应被gzip压缩。

How do we properly ask Indy 10 to issue HTTP 1.1 POST requests? 我们如何正确地要求Indy 10发出HTTP 1.1 POST请求?

Thank you! 谢谢!

Include the hoKeepOrigProtocol option into the HTTPOptions property set (set it to True). 包括hoKeepOrigProtocol选项进入HTTPOptions属性集(将其设置为True)。 Except that keep the ProtocolVersion property set to pv1_1 (which is the default value). 除了将ProtocolVersion属性设置为pv1_1 (这是默认值)。

In the TIdCustomHTTP.Post method code there's a comment explaining the current behavior: TIdCustomHTTP.Post方法代码中,有一条解释当前行为的注释:

Currently when issuing a POST, IdHTTP will automatically set the protocol to version 1.0 independently of the value it had initially. 目前,在发布POST时,IdHTTP将自动将协议设置为版本1.0,与其最初的值无关。 This is because there are some servers that don't respect the RFC to the full extent. 这是因为有些服务器完全不尊重RFC。 In particular, they don't respect sending/not sending the Expect: 100-Continue header. 特别是,他们不尊重发送/不发送Expect:100-Continue标头。 Until we find an optimum solution that does NOT break the RFC, we will restrict POSTS to version 1.0. 在我们找到不破坏RFC的最佳解决方案之前,我们将POSTS限制为1.0版。

A few lines below is the change to the version 1.0 with the following comment: 以下几行是对版本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;

And the above code is skipped (the version is not changed) if you have the hoKeepOrigProtocol option included in the HTTPOptions . 和上面的代码被跳过(版本不变),如果你有hoKeepOrigProtocol列入选项HTTPOptions

just need to write: 只需要写:

idHTTP.HTTPOptions:= [hoKeepOrigProtocol]; idHTTP.HTTPOptions:= [hoKeepOrigProtocol];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM