在 Red 中发出 POST 请求时如何在 headers 中使用变量

How to use a variable in headers when making a POST request in Red

我正在尝试使用 Red 语言发出 POST 请求。

我必须通过授权传递 header,并且我在发出请求并将其保存在变量 auth-string 之前计算授权字符串的值。

probe 打印 auth-string 值很好。

如果我 hard-code headers 部分中的授权字符串,它可以工作,但是当我尝试使用该变量时程序退出。

此代码与 hard-coded Authorization: "Basic c29tZX... 有效:

username: "someusernamestring"
password: "somepasswordstring"

url: to url! rejoin ["https://example.com/" username "/Account.json"]

auth-string: rejoin ["Basic " enbase/base rejoin [username ":" password] 64]
probe auth-string

response: write url [
        post [
        Content-Type: "application/x-www-form-urlencoded"
        Authorization: "Basic c29tZXVzZXJuYW1lc3RyaW5nOnNvbWVwYXNzd29yZHN0cmluZw=="
    ]
    {}    
]

print response

但是,带有变量 Authorization: auth-string 的这段代码不起作用,程序退出,没有我能看到的错误。

username: "someusernamestring"
password: "somepasswordstring"

url: to url! rejoin ["https://example.com/" username "/Account.json"]

auth-string: rejoin ["Basic " enbase/base rejoin [username ":" password] 64]
probe auth-string

response: write url [
        post [
        Content-Type: "application/x-www-form-urlencoded"
        Authorization: auth-string
    ]
    {}    
]

print response

如何在 headers 部分使用变量?

这应该像在 Rebol 中一样工作

response: write url compose/deep [
     post [
        Content-Type: "application/x-www-form-urlencoded"
        Authorization: (auth-string)
    ]
    {}    
]