我试图利用新的invoke-restmethod cmdlet来POST一个
JSON文件并成功完成了.但是,我没有像使用CURL时那样收到网络服务器的回复.对于我想要完成的任务,我需要从reposne获取信息到POST并将其用于另一个POST命令.
有人可以解释我如何从服务器获得预期的响应?下面是使用Invoke-RestMethod的两个命令1st in CURL,2nd命令. curl命令将执行正确的POST并返回响应. Powershell命令将执行正确的POST但不会返回响应.
谢谢
编辑:我认为我试图从ps输出获得的主要内容是“响应头”即. curl命令下面的输出
< HTTP/1.1 201 Created < Date: Thu,26 Jul 2012 01:20:06 GMT < Server: Apache < X-EM7-Implemented-methods: GET,PUT,POST < X-Powered-By: ScienceLogic,LLC - EM7 API/Integration Server < Location: /ticket/321750 < X-EM7-status-message: ticket /ticket/321750 added. < X-EM7-status-code: CREATED < Content-Length: 830 < Content-Type: application/json <
卷曲命令
curl -f -v -s -k --no-sessionid -H X-em7-beautify-response:1 -H content- type:application/json https://URLHERE --data-binary @jsonfile.json
Powershell代码
$cert=New-Object System.Security.Cryptography.X509Certificates.X509Certificate2("certfile.crt") $json = Get-Content jsonfile.json $cred = Get-Credential -Message "Enter Credentials" Invoke-RestMethod -Uri https://URLHERE -Credential $cred -Body $json -Certificate $cert -ContentType application/json -Method POST
解决方法
经过一番钓鱼后,我发现了cmdlet Invoke-WebRequest.此cmdlet与Invoke-RestMethod基本相同,不同之处在于它返回标头和响应.