Powershell 相当于 curl --resolve

Powershell 相当于 curl --resolve

我需要使用 powershell 检查未设置 DNS 条目或指向无法访问的 IP 的调用的 https 响应代码。该命令在与托管应用程序的 IIS 相同的服务器上运行。IIS 站点仅使用 https、下面显示的端口以及 DNS 名称“dns-name.com”和有效证书进行设置。我试过这个:

Invoke-WebRequest -Uri "$url" -Headers @{ Host="$httpHost" }

其中 $url 类似于:“https://127.0.0.1:1234/some.endpoint.svc”,而 $httpHost 类似于“dns-name.com”

失败了:

Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.

但是,下载 curl(查看这是否是 IIS 或 Powershell 问题)并使用它就可以了:

curl -s -o /dev/null -w "%{http_code}" https://dns-name.com:1234/some.endpoint.svc --resolve "dns-name.com:1234:127.0.0.1"

我的 powershell 尝试使用 http 运行良好,但使用 https 则不行。

相关内容