从URL下载文件失败,错误为500

时间:2016-03-11 11:23:32

标签: powershell

我想要做的是编写一个自动脚本,每天下载一个文件并将其保存在服务器上。 我遇到的第一个问题是网址的格式不是website.com/file.zip,而是http://www.website.com/LinkClick.aspx?fileticket=8pIcfhrhw%3d&tabid=900&mid=85。 我使用PowerShell进行了测试,我有以下错误:

Exception lors de l'appel de « DownloadFile » avec « 2 » argument(s) :
« The remote server returned an error : (500) Internal Server Error. »
At the level of C:\Users\me\test.ps1 : 5 Caractère : 24
+ $webclient.DownloadFile <<<< ($url, $file)
    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

如果你可以帮我批量生产,我也会接受它。我在Windows而不是Linux上工作。

我的剧本:

$storageDir = $pwd
$webclient = New-Object System.Net.WebClient
$url = "http://www.website.com/LinkClick.aspx?fileticket=8pIcfhrhw%3d&tabid=900&mid=85"
$file = "$storageDir\newdata.pdf"
$webclient.DownloadFile($url, $file)

0 个答案:

没有答案