powershell - Invoke-WebRequest 中的 URL 未按预期工作
问题描述
$dd = Get-Date -Format dd
$mn = Get-Date -Format MMM
$yr = Get-Date -Format yyyy
$umn = $mn.ToUpper()
$dt = $dd + $umn + $yr
$Zfile = 'cm'+$dt+'data.csv.zip'
$Tfile='DATA'+$dt+'.CSV'
$URL = 'https://archives.XYZ.com/content/historical/XYZ/'+$yr+'/'+$umn+'/'+$Zfile
Invoke-WebRequest -URI $URL -OutFile D:\MYDATA\$Zfile
#$URL
我有这个脚本,如果我打印 $URL 然后我可以看到 https 但是当在错误消息中运行脚本时我只能 http 这就是为什么面临“拒绝访问”
Invoke-WebRequest : Access Denied
You don't have permission to access "http://archives.XYZ.com/content/historical/XYZ/2021/JULY/MYFILE.csv.zip" on this server.
Reference #18.b5fdd417.1627307177.3a23ec35
At D:\mywork\XYZ.ps1:12 char:1
Invoke-WebRequest -URI $URL -OutFile D:\MYDATA\$Zfi ...
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand
解决方案
推荐阅读
- css - 如何在我的 React 项目中放置颜色叠加层(比如红色)?
- api - NoSuchMethodError: '[]' 从 Flutter 应用程序 api 重新调整的 null 动态调用
- python - PY selenium 上传base64图片
- arrays - MongoDB 库存系统:每个项目一个文档或一个数组
- python - PySpark - 运行计数()/聚合函数(平均等)时出现不一致
- c# - HttpListener 不使用显式前缀但使用模式前缀
- java - 代码说明(打印所有可能的长度为 K 的字符串)
- javascript - 'read_image' 已声明,但其值从不读取。ts(6133)
- r - 将一行数字/一个向量附加到R中矩阵的现有列
- c - 为什么在尝试比较字符数组时会出现分段错误?