加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

perl – HTTP ::请求用标题中的连字符替换下划线

发布时间:2020-12-15 21:47:25 所属栏目:大数据 来源:网络整理
导读:使用来自LWP :: UserAgent的HTTP :: Request指定包含下划线的自定义标头时,下划线将更改为连字符: use LWP::UserAgent;my $rq = HTTP::Request-new("GET","http://cpan.org");$rq-header("X-FOO_BAR","xyzzy");print $rq-as_string; 输出: GET http://cpan
使用来自LWP :: UserAgent的HTTP :: Request指定包含下划线的自定义标头时,下划线将更改为连字符:
use LWP::UserAgent;

my $rq = HTTP::Request->new("GET","http://cpan.org");
$rq->header("X-FOO_BAR","xyzzy");
print $rq->as_string;

输出:

GET http://cpan.org
X-FOO-BAR: xyzzy

有没有办法解决这个问题?

> perl v5.26.2
> LWP:UserAgent 1.9601
> linux 4.17.8-1-ARCH

解决方法

尝试使用前导命名头部:,根据“非正规字段名称”中的 HTTP::Headers中的文档:

The header field name spelling is normally canonicalized including the ‘_’ to ‘-‘ translation. There are some application where this is not appropriate. Prefixing field names with ‘:’ allow you to force a specific spelling.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读