gpt4 book ai didi

http - 在 HTTP header 中表示真值和假值的标准格式是什么?

转载 作者:行者123 更新时间:2023-12-04 15:38:43 27 4
gpt4 key购买 nike

我需要向 HTTP 请求添加自定义 header ,其值的类型将为 bool 值。但是,HTTP header 值都是字符串。那么在这种情况下表示 bool 值的常见做法是什么? 0/1 , false/true , False/True , off/on , 等等?

例如。

My-Header: 1

或者一般推荐什么,即最常用的约定?

最佳答案

更新:使用 header exists 可能最有意义对比 doesn't exist约定为 implied here
HTTP 头操作 http header .EXISTS

Returns a Boolean TRUE if an instance of the specified header type exists. Following is an example:

http.req.header("CacheControl").exists



我想答案是 ?0对比 ?1 Structured Field Values for HTTP > 3.3.6. Booleans

Boolean values can be conveyed in Structured Fields.

The ABNF for a Boolean is:

sf-boolean = "?" boolean

boolean = "0" / "1"


bool 值用前导“?”表示字符后跟“1”
为真值或“0”为假。例如:

Example-Boolean: ?1



退房 Sec-Fetch-User :

Syntax

Sec-Fetch-User: ?0

Sec-Fetch-User: ?1

Values

The value is a Boolean Structured Header.

?0 The navigation request was triggered by a user activation.

?1 The navigation request was triggered by something other than a useractivation.


但后来, Save-Data 似乎也是接受值的标准/官方“ bool 值” header "on"对比 "off" Save-Data

A boolean that indicates the user agent's preference for reduced datausage.


( https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers )

A numerical value indicating whether the client wants to opt in toreduced data usage mode. on indicates yes, while off (the default)indicates no.


同样令人困惑的是, ABNF page实际上说:

boolean = ( "true" / "1" ) /

( "false" / "0" )

关于http - 在 HTTP header 中表示真值和假值的标准格式是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58854683/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com