网站首页 美食营养 游戏数码 手工爱好 生活家居 健康养生 运动户外 职场理财 情感交际 母婴教育 时尚美容

Powershell:通过WebClient获取网络上的资源

时间:2024-10-12 09:17:22

1、创建WebClient对象:$web = New-Object System.Net.WebClient

2、设置文本的编码:$web.Encoding = [System.Text.Encoding]::UTF8

3、下载网页代码$str = $web.DownloadString("http://localhost")$str

4、获取文竭惮蚕斗件资源$url = "http://path.to/file"$file = &鳎溻趄酃quot;\\localpath\to\file"$web.DownloadFile($url,$file)

5、WebClient能够实现一个HTTP客户端,进而拓展的应用场景非常丰富,如 web自动化,网络爬虫,异步下载器等

© 2025 小知经验
信息来自网络 所有数据仅供参考
有疑问请联系站长 site.kefu@gmail.com