[Powershell] Call Restful Web API via Powershell

熱門文章 (Popular Post)

Posted by : Duran Hsieh 2017-08-08

Yesterday I would like to create a new  build script on TeamCity. This build script is for calling restful web api after performance test has been done. I don't want to install any plugins on project TeamCity server, so I decide to call restful web api via powershell.

We can use "Invoke-RestMethod" to  call restful web api as below:


$header = @{
     "Authorization"="Bearer iamtokenhahaha0123456789"

Invoke-RestMethod -Method Get -Uri "http://localhost/api/getDate" -Header $header


$params = @{
$header = @{

Invoke-RestMethod -Method Post -Uri "http://localhost/api/login" -Body $params -Header $header

POST (json format):

$json = @{
$header = @{

Invoke-RestMethod -Method Post -Uri "http://localhost/api/login" -Body (ConvertTo-Json $json) -Header $header

It is simple and easy to understand, right? :)

Leave a Reply

Subscribe to Posts | Subscribe to Comments

- Copyright © Duran Hsieh @ Duran 的技術冶煉廠 - Date A Live - Powered by Blogger - Designed by Johanes Djogan -