我正试图用红色语言发出一个post请求。
我必须传递带有授权的头,在发出请求并将其保存在变量中之前,我正在计算授权字符串的值
auth-string
.
probe
打印
验证字符串
值罚款。
如果我在头部分中硬编码授权字符串,它是有效的,但是当我尝试使用变量时,程序就退出了。
此代码带有硬编码
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部分使用变量?