2

I'm using Powershell v4.

I am calling a POST API and want to see the response when I run Invoke-RestMethod but it just shows a new line.

enter image description here

How can I output the response from the API to the console? I have tried running it in a script with Write-Host and Write-Output, but nothing appears on the console screen.

PowerShell script:

$Response = Invoke-RestMethod -Uri https://localhost:8081/myAPI -Body '{"username":"xyz","password":"xyz"}' -ContentType application/json -Method POST 
Write-Host $Response

I can see the response when I curl the API but cannot see it in my PowerShell script which I need to use.

CURL

curl -H "Content-Type: application/json" -X POST -d '{"username":"xyz","password":"xyz"}' https://localhost:8081/myAPI

It looks like its not even hitting the API as nothing appears in the API logs when triggering from Powershell. Not sure how to resolve that if that is the problem.

1

1 Answer 1

1

Your command has a syntax error. Your contenttype is not in proper format.

You have:

-ContentType application/json

Change it to:

-ContentType "application/json"
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.