Invoke-RestMethod 没有通过 headers

Invoke-RestMethod isn't passing headers

Invoke-RestMethod 遇到了一个非常奇怪的问题。我正在使用它发送 GET 并在请求中包含一个 cookie:

$getEndpoint = "http://YYYYYYYYYYYYYY/clients/XXXXXX/dev"
$authheader = "auth_tkt=\""XXX"""
Invoke-RestMethod -Headers @{"cookie" = "$authheader"} -Uri $getEndpoint 

如果我在 Fiddler 中查看请求,我会看到:

GET http://YYYYYYYYYYYYYY/clients/XXXXXX/dev HTTP/1.1 User-Agent: Mozilla/5.0 (Windows NT; Windows NT 6.1; en-GB) WindowsPowerShell/4.0 Host: YYYYYYYYYYYYYY Connection: Keep-Alive

饼干哪里去了? cookie 正在沿着管道的某个地方消失。任何想法为什么?我假设我在某处误解了什么。

以防万一,我已尝试从 curl 发出类似的请求并且它可以正常工作(即它使用提供的 cookie 进行身份验证并且我得到了我期待的响应):

curl -H "cookie: auth_tkt=\"XXX" http://YYYYYYYYYYYYYY/clients/XXXXX/dev

The invoke-restmethod's doc 说你不能通过 -headers 传递 cookie:

Headers Specifies the headers of the web request. Enter a hash table or dictionary. To set UserAgent headers, use the UserAgent parameter. You cannot use this parameter to specify UserAgent or cookie headers

另一种方法是使用 webclient 和 cookieContainer;看看 post :