Javascript 在powershell脚本中下载文件
我正在试图找到一种在powershell脚本中下载文件的方法。从网站端,我可以看到URL为:Javascript 在powershell脚本中下载文件,javascript,powershell,https,download,Javascript,Powershell,Https,Download,我正在试图找到一种在powershell脚本中下载文件的方法。从网站端,我可以看到URL为: https://website.com/admin/listCC.cfm?reportCode=105&clientId=11111&beginDate=04/01/2016 00:00&endDate=04/01/2016 23:59&download 单击IE中的链接将给出保存、另存为或打开提示,它是一个TXT文件。我也尝试过使用webclient代码调用webre
https://website.com/admin/listCC.cfm?reportCode=105&clientId=11111&beginDate=04/01/2016 00:00&endDate=04/01/2016 23:59&download
单击IE中的链接将给出保存、另存为或打开提示,它是一个TXT文件。我也尝试过使用webclient代码调用webrequest,但输出总是这样:
<html>
<head>
<title> Session Timed Out</title>
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function sessionDone(){
alert('Your session has expired. Please login again.');
window.location = "/admin/logout.cfm";
}
//-->
</SCRIPT>
<meta http-equiv="Pragma" content="no-cache" />
<meta http-equiv="cache-control" content="no-store" />
<meta http-equiv="Expires" content="-1" />
</head>
<body onLoad="sessionDone();">
</body>
</html>
我很幸运,我试图获得的下载链接并不完全是独一无二的。我所要做的就是把昨天的日期传过去,以获取我需要的文件。看起来它缺少获取该页面的请求中的cookies。Dan,谢谢你的回复。你知道如何在请求中传递cookies吗?
$yesterday = (Get-Date).AddDays(-1).ToString('MM/dd/yyyy')
$loginsession=$null
$loginform=$null
$loginpage=$null
$login=$null
$dl_105=$null
$loginpage = Invoke-WebRequest ("https://website.com/loginpage") -SessionVariable loginsession
$loginform=$loginpage.Forms[0]
$loginform.fields["username"] = "username"
$loginform.fields["password"] = "password"
$login = Invoke-WebRequest -Uri ("https://website.com/" + $loginform.Action) -WebSession $loginsession -Method POST -Body $loginform.Fields
$dl_105=Invoke-WebRequest -Uri ("https://website.com/admin/listCC.cfm?reportCode=105&clientId=11111&beginDate=$yesterday 00:00&endDate=$yesterday 23:59&download") -Method GET -ContentType "text/csv" -Body $loginform.Fields -WebSession $loginsession
Out-File -FilePath C:\Users\Administrator\Desktop\test\new_test.txt -InputObject $dl_105.Content -encoding ASCII
sleep 5