将自定义标头添加到TIdHttp请求中,标头值带有逗号

问题描述:

我正在使用Delphi XE2和Indy 10.5.8.0。我有一个TIdHttp实例,我需要向请求添加一个自定义标头。标头值中包含逗号,因此会自动将其解析为多个标头。我不希望它那样做。我需要我的自定义标头的标头值仍然是一个字符串,而不是基于逗号分隔符。

I'm using Delphi XE2 and Indy 10.5.8.0. I have an instance of TIdHttp and I need to add a custom header to the request. The header value has commas in it so it's getting parsed automatically into multiple headers. I don't want it to do that. I need the header value for my custom header to still be one string and not split based on a comma delimiter.

我尝试设置 IdHttp1。 Request.CustomHeaders.Delimiter:=';'没有成功。有没有办法确保标头不会被拆分?

I have tried setting IdHttp1.Request.CustomHeaders.Delimiter := ';' with no success. Is there a way to make sure the header doesn't get split up?

procedure SendRequest;
const HeaderStr = 'URL-Encoded-API-Key VQ0_RV,ntmcOg/G3oA==,2012-06-13 16:25:19';
begin
  IdHttp1.Request.CustomHeaders.AddValue('Authorization', HeaderStr);
  IdHttp1.Get(URL);
end;


我无法使用最新版本重现此问题Indy 10.5.8 SVN快照。

I am not able to reproduce this issue using the latest Indy 10.5.8 SVN snapshot. The string you have shown gets assigned as a single line for me.

这样,默认情况下, TIdHeaderList.FoldLines 属性设置为True,并且行在空白和逗号字符处折叠,因此可以解释为什么字符串被拆分。据我所知,在您的Indy版本和SVN的最新版本之间,折叠算法没有进行任何逻辑更改。

With that said, by default the TIdHeaderList.FoldLines property is set to True, and lines get folded on whitespace and comma characters, so that would explain why your string is getting split. Near as I can tell, there have not been any logic changes made to the folding algorithm between your version of Indy and the latest version in SVN.