1

i found that the result $request.ContentType is difference by using char[] and String.

$request = [System.Net.HttpWebRequest].create($URL)

$request.ContentType = [char[]] "application/x-www-url-formurlened"
$request.ContentType = "application/x-www-url-formurlened"

What is the different in the actual output to the server side, if I made a request like that using char[] and string?

it is so confusing...i guess it should be the same

thanks

4

1 回答 1

5

我想我弄清楚了这个问题。看一下这个:

PS D:\> $foo = "bar"
PS D:\> $foo
bar
PS D:\> $faz = [string][char[]]"baz"
PS D:\> $faz
b a z

Powershell 会将您char[]转换为 a string,因为HttpRequest.ContentType它是 type ,但是当 Powershell 将数组转换为字符串时,它会在每个元素之间string插入特殊变量的值。about_special_variables$OFS的帮助包含有关(和其他内容)的信息。的默认值是解释此行为的空格。$OFS$OFS

(感谢 BartekB 在评论中指出 $OFS。)

于 2012-05-25T03:43:22.157 回答