新しい invoke-restmethod コマンドレットを使用して JSON ファイルを POST しようとしていますが、成功しました。ただし、CURL を使用したときのように Web サーバーからの応答がありません。私が達成しようとしているのは、reposne から POST に情報を取得し、これを別の POST コマンドに使用する必要があることです。
サーバーから期待される応答を取得する方法を誰か説明してもらえますか? 次の 2 つのコマンドは、1 番目は CURL で、2 番目は Invoke-RestMethod を使用しています。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