PowerShell:Invoke-WebRequest - 无法验证参数 'Uri' 的参数
PowerShell: Invoke-WebRequest - Cannot validate argument on parameter 'Uri'
我正在努力帮助一名开发人员,他试图加强 Web 服务器以防止服务器端请求伪造。简而言之,我编写了一个发送“伪造”HTTP 请求的脚本,我们将使用该请求对服务器进行测试,直到它被配置为不响应此类操纵请求。我在 Invoke-WebRequest 上遇到错误:“无法验证参数 'Uri' 上的参数”,虽然我尝试了下面代码的大量不同组合,但我无法让它运行。有什么想法吗? (注:以下my-ef.example.com并非实际主机)
#requires -Version 5
#requires -PSEdition Desktop
class TrustAllCertsPolicy : System.Net.ICertificatePolicy {
[bool] CheckValidationResult([System.Net.ServicePoint] $a,
[System.Security.Cryptography.X509Certificates.X509Certificate] $b,
[System.Net.WebRequest] $c,
[int] $d) {
return $true
}
}
[System.Net.ServicePointManager]::CertificatePolicy = [TrustAllCertsPolicy]::new()
$Params = @{
Uri = 'http://192.168.1.119'
Host = 'my-ef.example.com'
Method = 'GET'
Headers = @{"Cache-Control" = "no-cache, no-transform"; "Connection" = "close"; "Pragma" = "no-cache"}
}
Invoke-WebRequest -Method 'POST' -Uri $url
以上代码总是抛出错误:
Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The
argument is null or empty. Provide an argument that is not null or
empty, and then try the command again.
$url
从未在您的代码中指定。你是想 运行 这个吗?
Invoke-WebRequest @Params
我正在努力帮助一名开发人员,他试图加强 Web 服务器以防止服务器端请求伪造。简而言之,我编写了一个发送“伪造”HTTP 请求的脚本,我们将使用该请求对服务器进行测试,直到它被配置为不响应此类操纵请求。我在 Invoke-WebRequest 上遇到错误:“无法验证参数 'Uri' 上的参数”,虽然我尝试了下面代码的大量不同组合,但我无法让它运行。有什么想法吗? (注:以下my-ef.example.com并非实际主机)
#requires -Version 5
#requires -PSEdition Desktop
class TrustAllCertsPolicy : System.Net.ICertificatePolicy {
[bool] CheckValidationResult([System.Net.ServicePoint] $a,
[System.Security.Cryptography.X509Certificates.X509Certificate] $b,
[System.Net.WebRequest] $c,
[int] $d) {
return $true
}
}
[System.Net.ServicePointManager]::CertificatePolicy = [TrustAllCertsPolicy]::new()
$Params = @{
Uri = 'http://192.168.1.119'
Host = 'my-ef.example.com'
Method = 'GET'
Headers = @{"Cache-Control" = "no-cache, no-transform"; "Connection" = "close"; "Pragma" = "no-cache"}
}
Invoke-WebRequest -Method 'POST' -Uri $url
以上代码总是抛出错误:
Invoke-WebRequest : Cannot validate argument on parameter 'Uri'. The argument is null or empty. Provide an argument that is not null or empty, and then try the command again.
$url
从未在您的代码中指定。你是想 运行 这个吗?
Invoke-WebRequest @Params