与powershell的测试应用程序链接

与powershell的测试应用程序链接,powershell,web,Powershell,Web,我正在使用powershell进行一些监视,我想检查应用程序的jnlp 存在于网站上,可供下载。 我有到.jnlp的链接,目前我正在下载带有.navigate()的文件 我试图通过提供无效的文件名来捕获异常,但无效。 我还想下载应用程序,然后尝试删除文件,以便 检查它是否确实存在,但速度太慢,因为我有很多JNLP要检查 还有其他更简单、更优雅的方法吗?我想避免下载 我要测试的每个文件 使用.Net中的类怎么样?获取数据非常简单。这样, $webclient = new-object System

我正在使用powershell进行一些监视,我想检查应用程序的jnlp 存在于网站上,可供下载。 我有到.jnlp的链接,目前我正在下载带有.navigate()的文件

我试图通过提供无效的文件名来捕获异常,但无效。 我还想下载应用程序,然后尝试删除文件,以便 检查它是否确实存在,但速度太慢,因为我有很多JNLP要检查

还有其他更简单、更优雅的方法吗?我想避免下载 我要测试的每个文件

使用.Net中的类怎么样?获取数据非常简单。这样,

$webclient = new-object System.Net.WebClient
try {
    # Download data as string and store the result into $data
    $data = $webclient.DownloadString("http://www.google.com/")
} catch [Net.WebException] {
    # A 404 or some other error occured, process the exception here
    $ex = $_
    $ex.Exception
}
使用.Net中的类怎么样?获取数据非常简单。这样,

$webclient = new-object System.Net.WebClient
try {
    # Download data as string and store the result into $data
    $data = $webclient.DownloadString("http://www.google.com/")
} catch [Net.WebException] {
    # A 404 or some other error occured, process the exception here
    $ex = $_
    $ex.Exception
}

如果您使用的是PowerShell 3.0或更高版本,则可以通过发出HTTP
HEAD
请求并检查状态代码,使用查看页面是否存在

$Result = Invoke-WebRequest -uri `http://bla.com/testApp.jnlp` -method head
if ($Result.StatusCode -ne 200){
    # Something other than "OK" was returned.
}

这在
System.Net.WebClient中也是可行的,但需要付出更多的努力。

如果您使用的是PowerShell 3.0或更高版本,您可以通过发出HTTP
HEAD
请求并检查状态代码来查看页面是否存在

$Result = Invoke-WebRequest -uri `http://bla.com/testApp.jnlp` -method head
if ($Result.StatusCode -ne 200){
    # Something other than "OK" was returned.
}
这在
System.Net.WebClient
中也是可行的,但需要付出更多的努力