将自定义标头添加到TIdHttp请求中,标头值带有逗号 [英] Adding custom header to TIdHttp request, header value has commas

查看:394
本文介绍了将自定义标头添加到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.

这篇关于将自定义标头添加到TIdHttp请求中,标头值带有逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆