Powershell 调用Webrequest不会发布登录表单

Powershell 调用Webrequest不会发布登录表单,powershell,post,http-headers,http-post,httpwebrequest,Powershell,Post,Http Headers,Http Post,Httpwebrequest,我正在尝试获取一些本地网页的信息,需要登录才能访问 我能跑 $response = Invoke-WebRequest "http://web.com/admin/launch?script=rh&template=dashboard" -SessionVariable rb -UserAgent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.30

我正在尝试获取一些本地网页的信息,需要登录才能访问

我能跑

$response = Invoke-WebRequest "http://web.com/admin/launch?script=rh&template=dashboard" -SessionVariable rb -UserAgent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'
$response
包含正确的信息,包括一个名为
login\u form
的表单,我需要使用该表单

然后,我写:

$response.Forms[0].Fields.user_id = 'admin'
$response.Forms[0].Fields.password= 'pass'
$response.Forms[0].Fields

Key       Value  
---       -----  
d_user_id user_id
t_user_id string 
c_user_id string 
e_user_id true   
user_id   admin  
password  pass  
我希望下面的命令返回登录后重定向到的页面的数据

Invoke-WebRequest $('http://web.com/admin/' + $response.Forms[0].Action) -WebSession $rb -Body $response.Forms[0].Fields -Method POST -contentType "application/x-www-form-urlencoded"
但是,这只是重新返回上一页,包括
登录表单
对象。它与
$response
相同,尽管请求似乎完全不同。

我认为这个问题源自每个页面使用的相同URL,不同的查询字符串参数(例如,
script=rh&template=login&action=login
)返回不同的页面。但是,我确实以字符串或
操作
属性的形式将这些字符串包含在我的
-URI
参数中。因此,如果我的POST请求能够正常工作,我不确定我还将使用什么方法返回正确的页面

我完全被困在这里,没有任何错误需要解决。我认为我在请求中没有犯任何错误,因为我花了很长时间调整参数(定义字段的不同语法等),这没有什么区别


chromehar文件:

我终于找到了答案。表单还需要其他字段。运行JS来重新命名表单中的字段,因此当我获取登录对象时,我填充了“错误”字段,因为在发布表单时调用Webrequest不会运行JS。在与Fiddler玩了很长一段时间后,我终于注意到,成功登录是这些字段命名稍有不同的结果。结果是这样的:

$response = Invoke-WebRequest "http://web.com/admin/launch?script=rh&template=login" -SessionVariable x -UserAgent 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'

$response.Forms[0].Fields.Add('f_user_id','admin')
$response.Forms[0].Fields.Add('f_password','')

$null = Invoke-WebRequest $('http://web.com/admin/' + $response.Forms[0].Action) -WebSession $x -Body $response.Forms[0].Fields -Method POST -contentType "application/x-www-form-urlencoded"

Invoke-WebRequest 'http://web.com/admin/launch?script=rh&template=dashboard' -WebSession $x

您是想严格地在“控制台”中执行此操作,还是可以使用IE创建浏览器会话?类似于
$ie=New Object-ComObject'internetExplorer.Application'$ie.Visible=$true
@brycemandal的东西不幸的是,这确实需要在控制台中。您如何才能成功“登录”?你只是抓住了答案。我看不到任何身份验证?您似乎没有登录?@AussieJoe我正在向action URI提交一篇文章,其中包含正确的登录字段(user,pass)。这与我读过的许多关于该主题的教程完全相同。@aussiecoe该网站不支持SSL。这是一个内部页面