powershell - 如何用powershell下载文件?
问题描述
过去我确实使用过:
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
$url = "https://nodejs.org/dist/v14.17.6/node-v14.17.6-x64.msi"
$folder = "C:\Users\test\Downloads"
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($url, $folder)
当我今天尝试时,它显示此错误
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At line:1 char:5
+ $WebClient.DownloadFile($url, $folder)
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
我试图用找到的建议来修复,但没有一个奏效。
解决方案
您需要提取文件名,以便获得 outfile 的完整路径,但这将起作用:
$url = "https://nodejs.org/dist/v14.17.6/node-v14.17.6-x64.msi"
$fullPath = "C:\Users\test\Downloads\node-v14.17.6-x64.msi"
Invoke-WebRequest $url -outfile $fullPath
推荐阅读
- javascript - 返回在 JavaScript 的嵌套循环中匹配的子项
- python - 通过导数实现具有两个隐藏层的多层感知器
- wso2-am - 为 wso2 api manager 3.2.0 配置负载均衡器
- c++ - SQL 数字/十进制以提高多精度
- node.js - 如果请求在nodejs中完成的时间太长,如何进行静态响应
- r - 更改一个堆叠条的字体颜色
- bash - 通过终端访问桌面文件夹
- python - 奇怪的AttributeError:'pygame.Surface'对象没有属性'rect'
- reactjs - 电子商务购物应用愿望清单和购物车物品清单是否需要分页
- laravel - 如何在 Laravel 8 中将 API 更改为 Json API。*