0

I can log in with

curl -user username:password https://testrail01.ando.pay1-test.de/index.php?/auth/login/ When i afterwards try to get some projects with

curl https://testrail01.ando.pay1-test.de/index.php?/api/v2/get_projects i have no authentification.

How can i set a cookie?

I tried

curl -user username:password --cookie-jar cookie.txt https://testrail01.ando.pay1-test.de/index.php?/auth/login but get the error: Invoke-WebRequest : Es wurde kein Positionsparameter gefunden, der das Argument "cookie.txt" akzeptiert. In Zeile:1 Zeichen:1 curl -user ... --cookie-jar c ...

thanks

Peter
  • 87
  • 1
  • 6
  • The linked duplicate talks about `Invoke-RestMethod`, but the approach is exactly the same with `Invoke-WebRequest` – Mathias R. Jessen Oct 25 '21 at 10:19
  • ok, I can set a cookie with $session = [Microsoft.PowerShell.Commands.WebRequestSession]::new() $cookie = [System.Net.Cookie]::new('cookieName', 'value') $session.Cookies.Add('https://domain.tld/', $cookie) but how can I now set the username and password to the cookie? – Peter Oct 25 '21 at 10:54
  • Usually (depending on authn mechanism) you'd do an initial request with the credentials encoded in the `Authorization` header and the web server will set a cookie with a session cookie. To intercept the cookie set by the server, use `Invoke-WebRequest -SessionVariable mySessionVar`, and then pass `$mySessionVar` on subsequent requests, eg. `Invoke-WebRequest -WebSession $mySessionVar` – Mathias R. Jessen Oct 25 '21 at 11:11
  • Thanks Mathias, I tried so: curl -user username:password https://testrail01.ando.pay1-test.de/index.php?/auth/login -SessionVariable mySessionVar and then curl -WebSession $mySessionVar https://testrail01.ando.pay1-test.de/index.php?/api/v2/get_projects . But I get the error: curl : {"error":"Authentication failed: invalid or missing user\/password or session cookie."} In Zeile:1 Zeichen:1 + curl -WebSession $mySessionVar https://testrail01.ando.pay1-test.de/i .. – Peter Oct 25 '21 at 13:32
  • `Invoke-WebRequest` is _not_ `curl`, it doesn't have quite the same parameter names. You'll want to create the credential with `Invoke-WebRequest -Credential ([pscredential]::new("username", $("password" |ConvertTo-SecureString -AsPlainText -Force)))` – Mathias R. Jessen Oct 25 '21 at 13:48
  • sry, I understand nothing :(. I'm absolut new to this topic. I tried: Invoke-WebRequest -SessionVariable 'mySessionVar' -user username:password -Uri https://testrail01.ando.pay1-test.de/index.php?/auth/login That was ok. But Invoke-WebRequest -WebSession $mySessionVar "https://testrail01.ando.pay1-test.de/index.php?/api/v2/get_projects" was -> authorization failed – Peter Oct 25 '21 at 14:39

0 Answers0