我有一段旧代码(单个 .aspx 文件),需要通过代理获取。这段代码曾经有效,但现在公司加强了安全性。
有问题的代码行是:
dataSet.ReadXml(url);
网址是 https。
它在 .NET 2.0 版上运行 - 这无法升级。我无法更改 web.config 文件。
我需要向 .aspx 文件添加什么才能使其工作?我得到的错误是:
The remote server returned an error: (407) Proxy Authentication Required.
脚本中没有“连接到网络”代码。
编辑
根据丹的评论,我试过这个:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
IWebProxy proxy = request.Proxy;
WebProxy myProxy = new WebProxy();
Uri newUri = new Uri("http://10.79.30.190:8080");
// Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
myProxy.Address = newUri;
// Create a NetworkCredential object and associate it with the
// Proxy property of request object.
myProxy.Credentials = new NetworkCredential("username", "password");
request.Proxy = myProxy;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
System.Data.DataSet dataSet = new System.Data.DataSet();
dataSet.ReadXml(responseString);
但我仍然遇到同样的错误
编辑
另一种尝试:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
IWebProxy proxy = request.Proxy;
WebProxy myProxy = new WebProxy();
Uri newUri = new Uri("http://10.79.30.190:8080");
// Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
myProxy.Address = newUri;
// Create a NetworkCredential object and associate it with the
// Proxy property of request object.
myProxy.Credentials = new NetworkCredential("username", "password");
request.Proxy = myProxy;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.Data.DataSet dataSet = new System.Data.DataSet();
dataSet.ReadXml(new StreamReader(response.GetResponseStream()));
但我仍然遇到同样的错误
慕森王
相关分类