- May 27, 2016 at 11:17 am #40559
I have this scenario:
I go to http://somepage.com/login
the page set cookie and display login form
I enter credentials, the page accept it,set some more cookies and redirect me (302) to main page.
I try to implement this scenario in powershell with Invoke-WebRequest
$siteurl = 'http://somepage.com' $r1 = Invoke-WebRequest -Uri ($siteurl+'/login') -SessionVariable mysession $r1.Forms.Fields['Login']='admin' $r1.Forms.Fields['Password']='password' $r2 = Invoke-WebRequest -Uri ($siteurl+$r1.forms.Action) - WebSession $mysession -Method Post -Body $r1.Forms.Fields
...and I can't login because while I get redirected within $r2 request
site set some more cookies but when redirected doesn't use these cookies!
NetCapture looks like
request: GET /Login response: 200 OK response: Set-Cookie Cookie1 request: GET /Login-Proceed (Action url) request: Cookie: Cookie1 response: 302, Location /Main response: Set-Cookie Cookie2 request: GET /Main request: Cookie: Cookie1 !!!!!! request: Cookie: Cookie2 missed here !!!!!
IE set both cookies on this stage
Anyone already meet these problems ? Any thoughts, workarounds ?
(yes, i know about COM IE object, System.Net.WebClient and so on, but I hoped to use the generic way 🙂May 30, 2016 at 10:37 am #40896
for those who are interested, a quick and dirty workaround
not well tested but suitable for my needs
You must be logged in to reply to this topic.