Forked from haraldfianbakken/PowerShell - Simple REST-Api testing
Created
February 2, 2021 15:37
-
-
Save raphaelcarlosr/ed6f38cdbfc177afb9dd2b9cb69414b0 to your computer and use it in GitHub Desktop.
Revisions
-
haraldfianbakken created this gist
Apr 20, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,29 @@ # Simple PowerShell script to load-test / test REST api with headers and cookies. # Harald S. Fianbakken $headers = @{ "Accept"= "application/zip"; "Accept-Encoding"= "gzip,deflate,sdch"; "My-Token-ID" = "This_is_a_test"; }; function Create-Cookie($name, $value, $domain, $path="/"){ $c=New-Object System.Net.Cookie; $c.Name=$name; $c.Path=$path; $c.Value = $value $c.Domain =$domain; return $c; } $ws = New-Object Microsoft.PowerShell.Commands.WebRequestSession; $ws.Cookies.Add((Create-Cookie -name "MyCookie1" -value "1871" -domain "fianbakken.com")); $ws.Cookies.Add((Create-Cookie -name "MyCookie2" -value "Hello world" -domain "fianbakken.com")); $api = "http://fianbakken.com/api/user/data" $result = Invoke-RestMethod -Method Get $api -WebSession $ws -Headers $headers; # Load-testing (from 1 machine), call 10 times and measure times # $command = [scriptblock]{(1..10|%{ $result = Invoke-RestMethod -Method Get $api -WebSession $ws -Headers $headers;})} # Measure-Command -Expression $command