質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.49%
PowerShell

Windows PowerShellはコマンドラインインターフェースであり、システム管理を含むWindowsタスク自動化のためのスクリプト言語です。

Q&A

解決済

1回答

2122閲覧

Postmanで成功するリクエストをPowerShellで送ると失敗する

emrair330

総合スコア19

PowerShell

Windows PowerShellはコマンドラインインターフェースであり、システム管理を含むWindowsタスク自動化のためのスクリプト言語です。

0グッド

0クリップ

投稿2022/07/15 09:41

前提

PostmanでPATCHリクエストに応答があることを確認したうえで、
PowerShellにて同じリクエストを送信すると403エラーになってしまいます。

powershell

1Invoke-RestMethod -Uri $url -Body ($body|ConvertTo-Json) -Method 'patch' -Credential $cred -ContentType 'application/json'

実現したいこと

Postmanと同様の変動が返ってくること。

発生している問題・エラーメッセージ

Invoke-RestMethod : Error 403--Forbidden Error 403--Forbidden From RFC 2068 Hypertext Transfer Protocol -- HTTP/1.1: 10.4.4 403 Forbidden The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated. If the request method was not HEAD and the server wishes to make public why the request has not been fulfilled, it SHOULD describe the reason for the refusal in the entity. This stat us code is commonly used when the server does not wish to reveal exactly why the request has been refused, or when no other response is applicable. 発生場所 行:1 文字:1 + Invoke-RestMethod -Uri $url -Body ($body|ConvertTo-Json) -Method 'pat ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod]、WebException + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

試したこと

$bodyの中身がPostmanと一致していることは確認済みです。

オプションの過不足なども確認していますが…
Invoke-RestMethodのリファレンスを見ても不足はないように思えます。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

emrair330

2022/07/15 10:43

署名まわりが怪しいかもしれません。
guest

回答1

0

自己解決

自己解決しました。

PowerShell

1-Credential $cred

↓↓↓

powershell

1-Headers @{ "Authorization" = "Basic " + $token }

認証の方式でエラーになってたんですかね…?
-Credentialの仕組みがよくわかってないので落ち着いたら勉強します。

投稿2022/07/15 13:14

emrair330

総合スコア19

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.49%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問