rest - Basic authentication script only works the first time -


i working bit on powershell script have can modify files , folders on url through rest calls, using invoke-restmethod, guess applies invoke webrequests or in general trying make work equivalent of how curl "username:password@host:port/path" work in linux.

my issue need pass credentials in curl. works fine doing first call when pass credentials using -credential problem when want perform further operations in script or use second time right after, no longer being prompted , script hangs.

the relevant part of code:

$securepassword = convertto-securestring "mypass" -asplaintext -force $credentials = new-object system.management.automation.pscredential("myuser",$securepassword) $uri = "http://myhost:myport/mypath/"  invoke-restmethod -uri $uri -credential $credentials -method delete 

this works totally fine first time run, second time hang , guessing because credential prompt doesn't come because stored while. can make several calls using curl right after each other no issues.

to me sounds need pass sort of authorization item in subsequent requests. in few rest applications have built goes this:

  1. send request credentials.
  2. receive response indicating authentication/log-in successful. response should include item (a key?) append subsequent requests.
  3. include authorization token in subsequent requests. recent rest app built uses userid obtain api key, , in subsequent requests sends key/val pair in header 'x-api-key' => 'theactualkeyvalue'. perhaps can similar.

Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -