以下代码是一个 powerShell 脚本,用于发送 POST 请求并获取响应并将其存储到$response. 当我尝试获取表单值并将其存储到 时$wa,它会自动打开浏览器。
$destination="https://adfs.somedomain.com/adfs/ls/";
$response = '';
$username = 'some username';
$password = 'some password';
$AuthMethod = 'FormsAuthentication';
$postParams = @{
destination="$destination";
flags='0';
forcedownlevel='0';
trusted='0'
UserName="$($username)";
Password="$($password)";
AuthMethod = "$($AuthMethod)";
isUtf8='1'
}
$url = "$($destination)?wa=wsignin1.0&wtrealm=urn:federation:cas"
$response = Invoke-WebRequest -uri $url -Method POST -body $postParams;
$wa = $response.InputFields.value[0];
Run Code Online (Sandbox Code Playgroud)
如何让脚本不打开浏览器?
注意:它发送 post 请求,该请求通过 get 请求返回到相同 uri 的重定向,并使用我试图存储在变量中的一些表单值进行响应。
此代码返回网站的移动版本.如何获得桌面版本?
InputStreamReader page = new InputStreamReader(new URL('http://www.***.com/').openStream());
Run Code Online (Sandbox Code Playgroud)