Why is Invoke-WebRequest not providing the Body?

时间:2018-03-02 18:50:24

标签: powershell

I have a very simple we server that takes a body and outputs it into an html response here is an example using a simple browser wrapper...

Sorry too new for images :-) < / p>

但是当我试图调用via Powershell's utility时,身体会变回空洞。这是Powershell代码......

$Body = 'TODO'
# Shows TODO
Write-Host $Body
$LoginResponse = Invoke-WebRequest 'http://localhost:8080/ping' -Body $Body -Method 'POST'
# WTF no TODO
Write-Host $LoginResponse

...

PS ..> .\SendToDashboard.ps1
TODO
<html>
<body>
<h1> Post Pong </h1>
<div></div>
</body>
</html>

我错过了为什么不使用-Body标志?

1 个答案:

答案 0 :(得分:1)

使用-ContentType "text/plain"设置内容类型标题,使其与示例应用程序具有相同的行为。

来自Invoke-WebRequest ContentType的文档:

  

如果省略此参数且请求方法为POST,则Invoke-WebRequest将内容类型设置为application / x-www-form-urlencoded。否则,呼叫中未指定内容类型。

相关问题