使用代理的服务器,无法使用WebClient。报错:无法解析此远程名称: 'www.***.com'的解决方法

使用代理的服务器,无法使用WebClient。报错:无法解析此远程名称: 'www.***.com'的解决方法

这段时间用WebClient做了一个小的爬取工具。在VS上调试一切正常。发布的IIS上就爬取不到了,直接报错:无法解析此远程名称: ‘www.***.com’。百度了一下大都是更改hosts,添加要爬取的网址;我也试了一下,并没有解决。偶然看到了一句 有可能是代理的问题。这段时间这客户这驻场还真是使用的代理上网。就试了一下,完美解决。
给WebClient使用代理的代码如下:

WebClient myWebClient = new WebClient();
string txtHost = 代理地址
int txtPort =代理端口
string txtUserName =代理账户 用户名
string txtPwd =代理账户 密码
NetworkCredential cre = new NetworkCredential(txtUserName, txtPwd);
WebProxy proxy = new WebProxy(txtHost, txtPort) { Credentials = cre };
myWebClient.Proxy = proxy;
PS C:\Users\29386\segment-anything\Grounded-Segment-Anything\CARLA> Invoke-WebRequest -Uri "https://carla-releases.s3.eu-west-3.amazonaws.com/Windows/CARLA_0.9.14.zip" ` >> -OutFile "CARLA_0.9.14.zip" ` >> -MaximumRedirection 10 ` # 增加重定向深度 Invoke-WebRequest : 远程服务器返回错误: (301) 已移动的永久重定向。 所在位置 行:1 字符: 1 + Invoke-WebRequest -Uri "https://carla-releases.s3.eu-west-3.amazonaws ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest],WebExce ption + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand PS C:\Users\29386\segment-anything\Grounded-Segment-Anything\CARLA> -UseBasicParsing ` # 避免 DOM 解析错误 -UseBasicParsing : 无法将“-UseBasicParsing”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果 包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 19 + -UseBasicParsing ` # 避免 DOM 解析错误 + ~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (-UseBasicParsing:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\29386\segment-anything\Grounded-Segment-Anything\CARLA> -SkipCertificateCheck ` # 忽略证书验证(PS 7+) -SkipCertificateCheck : 无法将“-SkipCertificateCheck”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的 拼写,如果包括路径,请确保路径正确,然后再试一次。 所在位置 行:1 字符: 19 + -SkipCertificateCheck ` # 忽略证书验证(PS 7+) + ~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (-SkipCertificateCheck:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException PS C:\Users\29386\segment-anything\Grounded-Segment-Anything\CARLA> -TimeoutSec 1800 -TimeoutSec : 无法将“-TimeoutSec”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径, 请确保路径正确,然后再试一次。 所在位置 行:1 字符: 19 + -TimeoutSec 1800 + ~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (-TimeoutSec:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
07-29
PS C:\Users\29386\segment-anything\Grounded-Segment-Anything\CARLA> [System.Net.ServicePointManager]::SecurityProtocol = >> [System.Net.SecurityProtocolType]::Tls12 -bor >> [System.Net.SecurityProtocolType]::Tls13 PS C:\Users\29386\segment-anything\Grounded-Segment-Anything\CARLA> $PSVersionTable.PSVersion Major Minor Build Revision ----- ----- ----- -------- 5 1 26100 4652 PS C:\Users\29386\segment-anything\Grounded-Segment-Anything\CARLA> Invoke-WebRequest -Uri "https://carla-releases.s3.eu-west-3.amazonaws.com/Windows/CARLA_0.9.14.zip" ` >> -OutFile "CARLA_0.9.14.zip" ` >> -MaximumRedirection 10 ` >> -UseBasicParsing ` # 5.1需要此参数 Invoke-WebRequest : 远程服务器返回错误: (301) 已移动的永久重定向。 所在位置 行:1 字符: 2 + Invoke-WebRequest -Uri "https://carla-releases.s3.eu-west-3.amazonaw ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest],WebExce ption + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand PS C:\Users\29386\segment-anything\Grounded-Segment-Anything\CARLA> -TimeoutSec 1800 -TimeoutSec : 无法将“-TimeoutSec”项识别为 cmdlet、函数、脚本文件或可运行程序的名称。请检查名称的拼写,如果包括路径, 请确保路径正确,然后再试一次。 所在位置 行:1 字符: 23 + -TimeoutSec 1800 + ~~~~~~~~~~~ + CategoryInfo : ObjectNotFound: (-TimeoutSec:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException
最新发布
07-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值