Delphi中的Indy 10:idHTTPRequest的POST请求总是HTTP 1.0版本,如何使其成为HTTP 1.1版本?

6
我们正在向Web服务发出POST请求。
工作正常。
然而,我们注意到请求始终是HTTP 1.0,这导致我们的Web服务器拒绝对响应进行gzip压缩。
如果请求是HTTP 1.1,则响应将被gzip压缩。
我们如何正确地要求Indy 10发出HTTP 1.1的POST请求?
谢谢!
2个回答

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;

如果在HTTPOptions中包含hoKeepOrigProtocol选项,上述代码将被跳过(版本不会改变)。


0

只需要写:

idHTTP.HTTPOptions:= [hoKeepOrigProtocol];


那已经在被接受的答案中了... 没有必要再说一遍相同的事情... - Jonesome Reinstate Monica

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接