Created
April 20, 2015 05:07
-
-
Save haraldfianbakken/7a1c719e26d187590522 to your computer and use it in GitHub Desktop.
This file contains 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 characters
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment