Powershell:通过WebClient获取网络上的资源
1、1.创建WebClient对象:
$web = New-Object System.Net.WebClient
2、2.设置文本的编码:
$web.Encoding = [System.Text.Encoding]::UTF8
3、3.下载网页代码
$str = $web.DownloadString("http://localhost")
$str
4、4.获取文件资源
$url = "http://path.to/file"
$file = "\\localpath\to\file"
$web.DownloadFile($url,$file)
5、WebClient能够实现一个HTTP客户端,进而拓展的应用场景非常丰富,如 web自动化,网络爬虫,异步下载器等
声明:本网站引用、摘录或转载内容仅供网站访问者交流或参考,不代表本站立场,如存在版权或非法内容,请联系站长删除,联系邮箱:site.kefu@qq.com。
阅读量:111
阅读量:20
阅读量:123
阅读量:58
阅读量:187