Powershell Invoke-WebRequest WebSession不起作用 [英] powershell Invoke-WebRequest WebSession not working

查看:60
本文介绍了Powershell Invoke-WebRequest WebSession不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法使以下代码正常工作.它似乎已登录,但随后返回带有$ response的登录页面.我猜这与回发有关吗?有什么解决的办法吗?谢谢!

I can't get the following code to work. It appears to log in but then returns the login page with $response. I am guessing it has something to do with the postbacks? Any way to get around that? Thanks!

$login = Invoke-WebRequest -Uri 'http://www.sqlpass.org/UserLogin.aspx' -SessionVariable sqlpass
$login.Forms[0].Fields["txtUsername_14615"] = 'myuser'
$login.Forms[0].Fields["txtPassword_14615"] = 'mypass'
$response = Invoke-WebRequest -Uri 'http://www.sqlpass.org/UserLogin.aspx' -WebSession $sqlpass -Method POST -Body $login

推荐答案

还有一个事件目标字段也需要设置,POST也需要一个不同的URL,我测试了以下解决方案,并且可以正常工作:

There is an event target field that also needs to be set, also the POST needs a different URL, i tested the solution below and it works:

$login = Invoke-WebRequest -Uri 'http://www.sqlpass.org/UserLogin.aspx' -SessionVariable sqlpass
$form = $login.Forms[0]
$form.Fields["__EVENTTARGET"] = "UserLogin"
$form.Fields["txtUsername_14615"] = 'myuser'
$form.Fields["txtPassword_14615"] = 'mypass'
Invoke-WebRequest -Uri 'http://www.sqlpass.org/UserLogin.aspx?returnurl=%2fdefault.aspx' -WebSession $sqlpass -Method POST -Body $form.Fields

注意:就像旁注一样,您可以使用 Fiddler 之类的Web调试代理来调试问题这样,这正是我所做的.

Note: Just as a side note, you can use Web Debugging proxies like Fiddler to debug issues like this, which is exactly what i did.

这篇关于Powershell Invoke-WebRequest WebSession不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆