Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save raphaelcarlosr/ed6f38cdbfc177afb9dd2b9cb69414b0 to your computer and use it in GitHub Desktop.

Select an option

Save raphaelcarlosr/ed6f38cdbfc177afb9dd2b9cb69414b0 to your computer and use it in GitHub Desktop.

Revisions

  1. @haraldfianbakken haraldfianbakken created this gist Apr 20, 2015.
    29 changes: 29 additions & 0 deletions PowerShell - Simple REST-Api testing
    Original 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