Bird
0
0

Which of the following is the correct syntax to send a GET request to https://api.example.com/data using Invoke-RestMethod?

easy📝 Syntax Q12 of 15
PowerShell - Cross-Platform PowerShell
Which of the following is the correct syntax to send a GET request to https://api.example.com/data using Invoke-RestMethod?
AInvoke-RestMethod -Url https://api.example.com/data -Method GET
BInvoke-RestMethod -Url https://api.example.com/data -Method POST
CInvoke-RestMethod -Uri https://api.example.com/data -Method FETCH
DInvoke-RestMethod -Uri https://api.example.com/data -Method GET
Step-by-Step Solution
Solution:
  1. Step 1: Identify correct parameter names and HTTP method

    The correct parameter for the URL is '-Uri' and the HTTP method for retrieving data is 'GET'.
  2. Step 2: Check each option for syntax correctness

    Invoke-RestMethod -Uri https://api.example.com/data -Method GET uses '-Uri' and '-Method GET' correctly. Invoke-RestMethod -Url https://api.example.com/data -Method POST uses '-Url' (incorrect parameter) and POST method. Invoke-RestMethod -Url https://api.example.com/data -Method GET uses '-Url' (incorrect parameter). Invoke-RestMethod -Uri https://api.example.com/data -Method FETCH uses an invalid HTTP method 'FETCH'.
  3. Final Answer:

    Invoke-RestMethod -Uri https://api.example.com/data -Method GET -> Option D
  4. Quick Check:

    Use -Uri and -Method GET for GET requests [OK]
Quick Trick: Use -Uri for URL and -Method GET for GET requests [OK]
Common Mistakes:
  • Using -Url instead of -Uri
  • Using -Method POST instead of GET
  • Using invalid HTTP methods like FETCH

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PowerShell Quizzes