出于某种原因,这不起作用
Invoke-RestMethod -Uri "http://localhost" -Headers @{"Host"="web.domain.com"}
我收到错误
The 'Host' header must be modified using the appropriate property or method
但是我找不到关于如何做到这一点的方法或属性。
由于
答案 0 :(得分:18)
这是PowerShell version 4.0中已修复的错误:
C:\PS> (irm http://localhost -Headers @{Host='web.domain.com'}).html
xmlns head body
----- ---- ----
http://www.w3.org/1999/xhtml head body
答案 1 :(得分: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)