Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/linq/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell命令:HttpWebRequest在获取两个请求后停止_Powershell - Fatal编程技术网

Powershell命令:HttpWebRequest在获取两个请求后停止

Powershell命令:HttpWebRequest在获取两个请求后停止,powershell,Powershell,我在一个文本文件中有一个URL列表,我想测试它们是否都是可访问的。我在windows powershell中启动了以下命令,但不知何故,在显示了前两个请求的状态后,该命令在某个地方死机,永远不会返回。我错过什么了吗 cat .\Test.txt | % { [system.Net.WebRequest]::Create("$_").GetResponse().StatusCode } 文本文件 http://www.google.com http://www.yahoo.com http://

我在一个文本文件中有一个URL列表,我想测试它们是否都是可访问的。我在windows powershell中启动了以下命令,但不知何故,在显示了前两个请求的状态后,该命令在某个地方死机,永远不会返回。我错过什么了吗

cat .\Test.txt | % { [system.Net.WebRequest]::Create("$_").GetResponse().StatusCode }
文本文件

http://www.google.com
http://www.yahoo.com
http://www.bing.com
输出:

OK
OK
----> after that it stucks.    

请改用Invoke WebRequest:

$sites = 'http://www.google.com','http://www.yahoo.com','http://www.bing.com'

foreach ($site in $sites) {

  Invoke-WebRequest $site
  $site

}

从内存:必须显式关闭响应流:

$req      = [System.Net.HttpWebRequest]::Create($aRequestUrl);
$response = $null

try
{
    $response = $req.GetResponse()

    # do something with the response

}
finally
{
    # Clear the response, otherwise the next HttpWebRequest may fail... (don't know why)
    if ($response -ne $null) { $response.Close() }
}

与上述行为相同
cat.\Test.txt |%{iwr“$\u”}
适合我-所以在powershell之外您遇到了一些问题