执行以下代码以获取 Web 服务器的值时,我收到此错误。
我已经阅读了一些可能的解决方案,这些解决方案涉及更改自己的 Web 服务器上的设置,但这对我来说不是一个选择,因为我不拥有服务器。
错误
使用“1”参数调用“DownloadString”的异常:“服务器违反协议。Section=ResponseStatusLine”在 C:\get.ps1:28 char:60 + $ramPage = (New-Object System.Net. WebClient).DownloadString <<<< ("http://" + $server + "/RAM/" + $evalRAMStars) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodException
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.
}