[英]Error when using DownloadString from a website using powershell
When executing the code below to get a value for a web server I get this error. 当执行下面的代码以获取Web服务器的值时,出现此错误。
I have read some possible solutions that involve changing setting on the web server it's self but this is not an option for me because I don't own the server. 我已经阅读了一些可能的解决方案,其中涉及更改Web服务器本身的设置,但这对我来说不是一个选择,因为我不拥有服务器。
Error 错误
Exception calling "DownloadString" with "1" argument(s): "The server committed a protocol violation. Section=ResponseStatusLine" At C:\\get.ps1:28 char:60 + $ramPage = (New-Object System.Net.WebClient).DownloadString <<<< ("http://" + $server + "/RAM/" + $evalRAMStars) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException 异常调用带有参数“ 1”的“ DownloadString”:“服务器犯了协议冲突。Section = ResponseStatusLine”在C:\\ get.ps1:28 char:60 + $ ramPage =(New-Object System.Net。 WebClient).DownloadString <<<<(“ http://” + $ server +“ / RAM /” + $ evalRAMStars)+ CategoryInfo:未指定:(:) [],MethodInvocationException + FullyQualifiedErrorId:DotNetMethodException
Powershell Code Powershell代码
Function Get-Performance(){
$CPU = Get-WmiObject win32_processor | Measure-Object -property LoadPercentage -Average | Select Average
$SystemInfo = Get-WmiObject -Class Win32_OperatingSystem | Select-Object Name, TotalVisibleMemorySize, FreePhysicalMemory
$perRam = (($SystemInfo.FreePhysicalMemory/1MB) / ($systeminfo.totalvisiblememorysize/1MB)) * 100
$perRam = 100 - $perRam
Write-host ("CPU: " + $CPU.Average + "%")
Write-host ("Ram: " + $perRam + "%")
$CPUStars = $CPU.Average / 10
$RAMStars = $perRam /10
if($CPUStars -lt 1){$CPUStars = 1}
Write-host ("{0:N0}" -f $CPUStars)
Write-host ("{0:N0}" -f $RAMStars)
$evalCPUStars = "{0:N0}" -f $CPUStars
$evalRAMStars = "{0:N0}" -f $RAMStars
$server = "10.0.0.188"
#this will get our page for later
$cpuPage = (New-Object System.Net.WebClient).DownloadString("http://" + $server + "/CPU/" + $evalCPUStars)
$ramPage = (New-Object System.Net.WebClient).DownloadString("http://" + $server + "/RAM/" + $evalRAMStars)
Write-host("http://" + $server + "/CPU/" + $evalCPUStars)
Write-host("http://" + $server + "/RAM/" + $evalRAMStars)
}
While($x -ne 0)
{
Get-Performance
Start-Sleep -s 10 #this will run the powershell script every 10 seconds.
}
The value of $evalRAMStars is probably causing the unsafe header parsing to block the message. $ evalRAMStars的值可能导致不安全的标头解析来阻止该消息。 Check that its value is valid. 检查其值是否有效。 Otherwise, see The server committed a protocol violation. 否则,请参阅服务器已违反协议。 Section=ResponseStatusLine ERROR for more solutions. Section = ResponseStatusLine ERROR以获取更多解决方案。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.