powershell - 区分 invoke-WebRequest 状态码
问题描述
我正在尝试在下载这些文件之前验证 URL,并且我想区分需要凭据的路径与错误路径之类的东西。
我现在有这个
function Get-UrlStatusCode([string] $Url) {
try {
return (Invoke-WebRequest -Uri $Url -UseBasicParsing -DisableKeepAlive -Method:head).StatusCode
} catch [Net.WebException] {
return "$([Int]$_.Exception.Response.StatusCode) $($_.Exception.Response.statusDescription)"
}
}
(Get-UrlStatusCode 'http://AWSBUCKETPATH/Test_Public.xml')
(Get-UrlStatusCode 'http://AWSBUCKETPATH/Test_Private.xml')
(Get-UrlStatusCode 'http://AWSBUCKETPATH/Test_Missing.xml')
对于公共路径,我得到预期的 StatusCode 200,但私有示例和缺少的示例都返回 403 Forbidden。这是我的代码中的故障,还是需要在 AWS 上进行配置才能为错误路径提供 404 Not Found,或者尽管存在 404 作为代码,但这不是可能的事情?
解决方案
推荐阅读
- javascript - 用于图像和文件的文件输入
- python-3.x - 如何设置脚本,以便每次在 google sheet 上有新的修改时,我的脚本都会被触发并执行一些操作
- python - ssmtp 无法通过电子邮件发送从 python 子进程收到的我的 bash 变量
- typescript - 防止在 Monorepo 中复制 Typescript 路径配置
- mongodb - Mongo 聚合在查找另一个集合后使用 $match
- javascript - javascript 模块的正确 mime 类型应该是什么?
- c - 将 2 列双精度的 .txt 转换为 2 个数组并读取它们
- python - 这个脚本可以使用模幂获得更好的性能吗?
- github-pages - Github Pages 没有检测到 repo 名称是我的用户名
- javascript - 使用带有条件的 ngFor 逗号分隔字符串?