为什么红语中的POST参数的第一个字符会自动变成大写?
Why POST in red language change the first character of parameters to upper-case automaticlly?
对于下面的简单代码,
Red []
#include %tools.red
url: to url! rejoin ["http://somesite.com:7466/japi"]
response: write url [
post [
Content-Type: "application/json"
req: "requestinfo"
list: "This is a pie."
]
{}
]
print response
结果类似于:
{"Status":"fail","Value":"unknown request: \u0026{POST /japi HTTP/1.1
1 1 map[Accept:[/] Content-Type:[application/json] Req:[requestinfo]
List:[This is a pie.] Content-Length:[0]] {} \u003cnil\u003e 0 []
false somesite.com:7466 map[] map[] \u003cnil\u003e map[]
176.116.100.233:31144 /japi \u003cnil\u003e \u003cnil\u003e \u003cnil\u003e 0xc0002a2640}"}
我的问题是,为什么参数(如req、list)会自动大写?
HTTP/1.1 RFC 在 section 4.2 中说:
Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.
因此,header 名称的第一个字符的大写在兼容的 HTTP 服务器上没有 side-effect。
不过,从您使用的“参数”术语和源代码中的 req: "requestinfo"
部分来看,我想知道您是否没有尝试将这些信息作为 POST 数据传递,错误地将它们放在 headers 列表中。如果是这样,那么传递它们的正确方法是:
Red []
#include %tools.red
url: http://somesite.com:7466/japi
response: write url [
POST [Content-Type: "application/json"]
"req=requestinfo&list=This%20is%20a%20pie."
]
print response
对于下面的简单代码,
Red []
#include %tools.red
url: to url! rejoin ["http://somesite.com:7466/japi"]
response: write url [
post [
Content-Type: "application/json"
req: "requestinfo"
list: "This is a pie."
]
{}
]
print response
结果类似于:
{"Status":"fail","Value":"unknown request: \u0026{POST /japi HTTP/1.1 1 1 map[Accept:[/] Content-Type:[application/json] Req:[requestinfo] List:[This is a pie.] Content-Length:[0]] {} \u003cnil\u003e 0 [] false somesite.com:7466 map[] map[] \u003cnil\u003e map[] 176.116.100.233:31144 /japi \u003cnil\u003e \u003cnil\u003e \u003cnil\u003e 0xc0002a2640}"}
我的问题是,为什么参数(如req、list)会自动大写?
HTTP/1.1 RFC 在 section 4.2 中说:
Each header field consists of a name followed by a colon (":") and the field value. Field names are case-insensitive.
因此,header 名称的第一个字符的大写在兼容的 HTTP 服务器上没有 side-effect。
不过,从您使用的“参数”术语和源代码中的 req: "requestinfo"
部分来看,我想知道您是否没有尝试将这些信息作为 POST 数据传递,错误地将它们放在 headers 列表中。如果是这样,那么传递它们的正确方法是:
Red []
#include %tools.red
url: http://somesite.com:7466/japi
response: write url [
POST [Content-Type: "application/json"]
"req=requestinfo&list=This%20is%20a%20pie."
]
print response