Ant*_*yer 11 powershell powershell-3.0
出于某种原因,这不起作用
Invoke-RestMethod -Uri "http://localhost" -Headers @{"Host"="web.domain.com"}
Run Code Online (Sandbox Code Playgroud)
我收到了错误
The 'Host' header must be modified using the appropriate property or method
Run Code Online (Sandbox Code Playgroud)
但我找不到如何做到这一点的方法或属性.
谢谢
Kei*_*ill 18
这是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
Run Code Online (Sandbox Code Playgroud)
为了记录,我使用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)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11195 次 |
| 最近记录: |