我正在尝试在网站上填写表格,提交表格,并在提交后获取已加载网站的输出。我必须使用PowerShell中的Invoke-Webrequest命令来完成此操作。
以下是应提交的表格:
<form id="login_form" action="/cgi-bin/posttest/printer/login.html" method="post">
<input type="hidden" name="login_type" value="password_only">
<input type="hidden" name="goto" value="/cgi-bin/dynamic/printer/config/reports/deviceinfo.html">
<input type="hidden" name="accid" value="13">
<table>
<tr><td>Password</td><td><input type="password" name="password" id="password" size="22" maxlength="128"/></td></tr>
</table>
<table>
<tr>
<td><input type="submit" value="Submit"></td><td> </td>
<td><input type="button" value="Cancel" onclick="history.go(-1);"></td>
</tr>
</table>
</form>
这是我尝试过的:
$url = "http://k0b1/cgi-bin/dynamic/printer/config/reports/deviceinfo.html"
$response = Invoke-WebRequest -Uri $url -Method Default -SessionVariable $sv
$form = $response.Forms[0]
$form.Fields["password"]="passwd"
$response = Invoke-WebRequest -Uri ($url + $form.Action) -WebSession $sv -Method POST -Body $form.Fields
$response.Content
在第二个 Invoke-WebRequest 之后,PowerShell返回与第一个相同的页面。注意:两个站点的URL相同。
我希望它返回提交表单后的网站。
感谢您的帮助