我在创建Powershell脚本以登录网站并下载文件时遇到了困难。该脚本似乎可以正常登录(我收到一个成功的状态返回),但当我尝试下载该文件时,我收到一条未经授权的消息。
代码如下:
$r=Invoke-WebRequest http://testurl/index.htm -SessionVariable fb
$form = $r.Forms[0]
$form.fields["loginusername"] = "user"
$form.fields["loginpassword"] = "pass"
$r=Invoke-WebRequest -Uri ("https://testurl/index.htm" + $form.Action) -WebSession $fb -Method POST -Body $form.Fields
Invoke-WebRequest -Uri "https://testurl/api/table.csv" -WebSession $fb -OutFile "C:\status\current.csv"感谢您的指导!
发布于 2017-10-27 21:48:53
我看过你想要引用的例子。当我尝试复制它时,它也有一些错误。我已经自动化了一些站点登录/下载;下面是一个可以尝试的调整:
$r=Invoke-WebRequest http://testurl/index.htm
$r.Forms.fields.loginusername = 'user'
$r.Forms.fields.loginpassword = 'pass'
Invoke-WebRequest -Uri 'https://testurl' + $form.Action) -SessionVariable fb -Method POST -Body $r
Invoke-WebRequest -Uri 'https://testurl/api/table.csv' -WebSession $fb -OutFile 'C:\status\current.csv'https://stackoverflow.com/questions/46976263
复制相似问题