我正在尝试在下载这些文件之前验证 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 作为代码,但这是不可能的?