使用 Powershell 和代理访问网络 [英] Access web using Powershell and Proxy
本文介绍了使用 Powershell 和代理访问网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我似乎无法使用 Powershell 访问网页.我不断收到(407)需要代理身份验证".我尝试了很多东西.我不知道代理是什么或者它需要什么样的身份验证.我唯一可以访问的是在 IE 中它使用脚本进行配置.我尝试使用其中的一些 IP,但没有运气.有任何想法吗?
I can't seem to get access to a webpage using Powershell. I keep getting a "(407) Proxy Authentication Required". I've tried many things. I don't know what the proxy is or what kind of authentication it requires. The only thing I have access to is in IE it uses a script for configuring. I tried using some IPs from that, but no luck. Any ideas?
这是我尝试过的一个例子:
Here is one example of what I tried:
$wc = New-Object System.Net.WebClient
$wc.Headers.Add("User-Agent","Mozilla/4.0+")
$wc.Proxy = [System.Net.WebRequest]::DefaultWebProxy
$wc.Proxy.Credentials = [System.Net.CredentialCache]::DefaultNetworkCredentials
$wc.DownloadString("http://stackoverflow.com")
推荐答案
我遇到了类似的问题,只用两行 powershell 就解决了:
I had a similar issue and resolved it with just two lines of powershell:
$browser = New-Object System.Net.WebClient
$browser.Proxy.Credentials =[System.Net.CredentialCache]::DefaultNetworkCredentials
希望这会有所帮助.
这篇关于使用 Powershell 和代理访问网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文