公司电脑域用户不允许下载,当我使用 WebRequest req = WebRequest.Create(UpdaterUrl);
WebResponse res = req.GetResponse(); 时就报:远程服务器返回错误 (401) 未经授权 解决方案 有人说使用System.Net.ServicePointManager.ServerCertificatidationCallback = new System.Net.Security.ServerCertificatidationCallback(CheckValidationResult);
,可我的在使用时报System.Net.ServicePointManager不包含ServerCertificatidationCallback 定义,我的是VS2008,不知道各位还有没有其他办法解决。
WebResponse res = req.GetResponse(); 时就报:远程服务器返回错误 (401) 未经授权 解决方案 有人说使用System.Net.ServicePointManager.ServerCertificatidationCallback = new System.Net.Security.ServerCertificatidationCallback(CheckValidationResult);
,可我的在使用时报System.Net.ServicePointManager不包含ServerCertificatidationCallback 定义,我的是VS2008,不知道各位还有没有其他办法解决。
我也就是使用的是它的。可是也还是不行。还是报同样的错误。
代码如下: //验证服务器证书回调自动验证
// System.Net.ServicePointManager.ServerCertificatidationCallback = new System.Net.Security.ServerCertificatidationCallback(CheckValidationResult);
//使用上面的报 System.Net.ServicePointManager 不包含 ServerCertificatidationCallback 定义。所以选择下面
ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(CheckValidationResult); if (!System.IO.Directory.Exists(downpath)) {
System.IO.Directory.CreateDirectory(downpath); }
string serverXmlFile = downpath + @"/" + clientXml; try {
WebRequest req = WebRequest.Create(UpdaterUrl);
WebResponse res = req.GetResponse();
if (res.ContentLength > 0) {
try {
WebClient wClient = new WebClient();
wClient.DownloadFile(UpdaterUrl, serverXmlFile);
} catch {
return string.Empty;
}
}
} catch (Exception ex) {
throw ex;
//MessageBox.Show("获取文件发生异常" + ex.Message,"系统提示"); }