Bird
0
0

You run this command but get an error:

medium📝 Debug Q14 of 15
PowerShell - Cross-Platform PowerShell
You run this command but get an error:
Invoke-RestMethod -Uri 'https://api.example.com/data' -Method POST -Body '{"name":"John"}'

What is the most likely cause?
AThe -Method POST is invalid; only GET is allowed.
BThe -Body parameter must be a PowerShell object, not a JSON string.
CThe URI is missing the protocol (http/https).
DInvoke-RestMethod cannot send POST requests.
Step-by-Step Solution
Solution:
  1. Step 1: Understand -Body parameter requirements

    Invoke-RestMethod expects the -Body parameter as a PowerShell object or properly formatted string with correct headers.
  2. Step 2: Identify issue with JSON string body

    Passing a raw JSON string without setting Content-Type header or converting to object causes errors.
  3. Final Answer:

    The -Body parameter must be a PowerShell object, not a JSON string. -> Option B
  4. Quick Check:

    Use objects or set headers when sending JSON body [OK]
Quick Trick: Send objects or set headers when posting JSON body [OK]
Common Mistakes:
  • Passing JSON string without Content-Type header
  • Assuming POST is unsupported
  • Omitting protocol in URI

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes