05 Powershell发送http请求

一:发送http请求

1、语法:

Invoke-WebRequest -uri "请求地址" -UseBasicParsing

2、实例:

$result = Invoke-WebRequest -uri  "http://rdc.mingyuanyun.com/rdc-service/api/v2/apps/$($app)/versions/maxpackversion"  -UseBasicParsing
#正则匹配规则
$parttern="\d{0,3}\.\d{0,3}\.\d{0,3}\.\d{0,3}" 
#匹配结果
$Status = "$result.Content" -match $parttern 
#版本号
$RdcVersion = $matches[0]
return $RdcVersion

二:http下载

1、语法:

#创建webclient对象;
$wc = New-Object net.webclient
#调用对象的Downloadfile方法下载
$wc.Downloadfile($downloadUrl,$zipPath)
$downloadUrl :下载的URL
$zipPath :存储目录及文件名

2、实例:

echo "===================拉取完整包-按版本号========================="
#拼接下载URL
$downloadUrl = "http://pkg.mingyuanyun.com/packages/$($app)/core-full/$endVersion/$endVersion.zip" 
$zipPath = "$ENV:WORKSPACE\CorePackage\ALL\$($app)_$endVersion.zip"
if(Test-Path $zipPath -PathType Leaf){
echo "::::::: 跳过下载,使用本地文件 $($zipPath) " 
}else{
echo "::::::: 下载 $($app) $($downloadUrl)"
$wc = New-Object net.webclient
$wc.Downloadfile($downloadUrl,$zipPath)
} 

你可能感兴趣的:(Powershell,http,网络协议,网络,batch,batch命令)