tcl - headers parameters in http::getUrl -
i passing headers parameters in http::geturl
-headers {authorization {bearer $token} content-type application/json}
but not substituting token value. right creating dict step above, , passing directly -headers $data
it way pass value directly, variable substitution occurs
this because string in {}
not evaluated, have 2 way here.
the first using list command:
-headers [list \ authorization [list bearer $token] \ content-type application/json ]
the second subst command:
-headers [subst -nocommands \ {authorization {bearer $token} content-type application/json}]
the first method proper used equivalent op example, different expression of list.
the purpose of second way, in case have parameter input variable, , not change format in code.
notice case subst
works on string , not list previous method.
it should work same string converted list easy:
$ tclsh % set x "a b c d" b c d % lindex $x 0 %
as see variable x
string, access list without problems.
Comments
Post a Comment