12

何らかの理由でこれが機能しない

Invoke-RestMethod -Uri "http://localhost" -Headers @{"Host"="web.domain.com"}

エラーが発生します

The 'Host' header must be modified using the appropriate property or method

しかし、これを行う方法に関するメソッドまたはプロパティが見つかりません。

ありがとう

4

2 に答える 2

19

これは、 PowerShell バージョン 4.0で修正されたバグです。

C:\PS> (irm http://localhost -Headers @{Host='web.domain.com'}).html

xmlns                                   head                                    body
-----                                   ----                                    ----
http://www.w3.org/1999/xhtml            head                                    body
于 2013-11-13T06:06:44.233 に答える
6

記録のために、私は WebRequest を使用して問題を回避しました

$bytes = [system.Text.Encoding]::UTF8.GetBytes("key=value")
$web = [net.WebRequest]::Create("http://localhost") -as [net.HttpWebRequest]
$web.ContentType = "application/x-www-form-urlencoded"
$web.Host = "web.domain.com"
$web.Method = "POST"
$web.ContentLength = $bytes.Length
$stream = $web.GetRequestStream()
$stream.Write($bytes,0,$bytes.Length)
于 2013-11-13T14:23:48.200 に答える