如何在Powershell中使用AngularJs表单自动登录网站?
我正在尝试在如何在Powershell中使用AngularJs表单自动登录网站?,angularjs,powershell,invoke-webrequest,Angularjs,Powershell,Invoke Webrequest,我正在尝试在powershell中编写一个脚本,该脚本将自动登录到使用AngularJS构建的网站,并将登录会话存储在变量中以供将来登录会话使用。是否有人能告诉/演示如何着手解决此问题?万分感谢 我以前做过,它总是很成功,只是在这种情况下,网站是用angularJs构建的,表单的InputFields隐藏在'Div'标记中。所以不起作用 以下是表单的外观: <form name="loginForm" class="login-form gf-form-group ng-pristine
powershell
中编写一个脚本,该脚本将自动登录到使用AngularJS
构建的网站,并将登录会话存储在变量中以供将来登录会话使用。是否有人能告诉/演示如何着手解决此问题?万分感谢
我以前做过,它总是很成功,只是在这种情况下,网站是用angularJs
构建的,表单的InputFields
隐藏在'Div'标记中。所以不起作用
以下是表单的外观:
<form name="loginForm" class="login-form gf-form-group ng-pristine ng-invalid
ng-invalid-required" ng-hide="disableLoginForm">
<!---->
<div class="gf-form" ng-if="loginMode">
<span class="gf-form-label width-7">User</span>
<input type="text" name="username" class="gf-form-input max-width-14 ng-
pristine ng-untouched ng-empty ng-invalid ng-invalid-required"
required="" ng-model="formModel.user" placeholder="email or username">
</div>
<!---->
<!---->
<div class="gf-form" ng-if="loginMode">
<span class="gf-form-label width-7">Password</span>
<input type="password" name="password" class="gf-form-input max-width-14
ng-pristine ng-untouched ng-empty ng-invalid ng-invalid-required"
required="" ng-model="formModel.password" id="inputPassword"
placeholder="password">
</div>
<!---->
<!---->
<div class="gf-form-button-row">
<button type="submit" class="btn btn-large
p-x-3 btn-inverse" ng-click="submit();" ng-class="{'btn-inverse':
!loginForm.$valid, 'btn-primary': loginForm.$valid}">Log in</button>
</div>
</form>
这是在Powershell
中运行脚本时出现的错误:
Cannot index into a null array.
At line:3 char:1
+ $Body = @{
+ ~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Invoke-WebRequest : [{"fieldNames":["User"],"classification":"RequiredError","message":"Required"}]
At line:10 char:18
+ ... nResponse = Invoke-WebRequest 'https://mywebsite/login' -WebSessi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
看起来可能是
ParsedHtml.forms
是一个零元素数组?@RossPresser,谢谢你的回答,但不是。此外,我认为这不是问题所在,因为脚本可以完美地与其他形式(非Restful api)配合使用,看起来可能是ParsedHtml。Forms
是一个零元素数组?@RossPresser,感谢您的回答,但不是。此外,我认为这不是问题所在,因为脚本与其他形式(非Restful api)完美配合
Cannot index into a null array.
At line:3 char:1
+ $Body = @{
+ ~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : NullArray
Invoke-WebRequest : [{"fieldNames":["User"],"classification":"RequiredError","message":"Required"}]
At line:10 char:18
+ ... nResponse = Invoke-WebRequest 'https://mywebsite/login' -WebSessi ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand