powershell - 如何使用 PowerShell 将 HTTP 请求版本更改为 1.0

标签 powershell

在 C# 中,我可以覆盖 WebClient.GetWebRequest 方法以更改 HTTP 版本。

protected override WebRequest GetWebRequest(Uri uri)  
{  
    HttpWebRequest request = (HttpWebRequest)base.GetWebRequest(uri);        
    request.ProtocolVersion = System.Net.HttpVersion.Version10;  

    return request;  
}

在使用 New-WebServiceProxy 调用 Web 服务之前,我必须将 HTTP 请求版本更改为 1.0。

有没有办法改变这个?

最佳答案

将 ProtocolVersion 字段设置为 version10。像这样,

$hr = [system.net.httpwebrequest]::create("http://www.example.com")
$hr.ProtocolVersion = [system.net.httpversion]::version10

请注意,与 C# 不同,Powershell(和 .Net API 绑定(bind))区分大小写。

关于powershell - 如何使用 PowerShell 将 HTTP 请求版本更改为 1.0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5405276/

相关文章:

azure - 使用外部参数通过 BICEP 脚本执行 AzurePowerShell

.net - WMI 类的原始值

forms - 如何使用 pwsh 中的新 param -form 登录网站

asp.net - 如何查找 IIS 功能的名称

Xpath 不是通过 Powershell 在 Select-Xml 中的运算符

powershell - 带有Pipe字符的字符串-如何避免将其误认为是逻辑OR?

powershell - 从客户端计算机修改 Active Directory 客户端 OU

linux - 管道文本到外部程序附加一个尾随换行符

powershell - 使用 SAS token 上传 Blob 内容

powershell - 在子域(跨林)中使用 Set-ADUser 和 Add-ADGroupMember 时出错