C# 如何访问代理后面的页面

C# 如何访问代理后面的页面,c#,authentication,webproxy,C#,Authentication,Webproxy,如果我硬编码我的凭证,则我的代码有效 string url; string proxyAddress; string user ; string password; Stream objStream; WebProxy proxyObject = new WebProxy(proxyAddress, true); proxyObject.Credentials = new NetworkCredential(user, password); WebRequest req = WebReques

如果我硬编码我的凭证,则我的代码有效

string url;

string proxyAddress;
string user ;
string password;
Stream objStream;
WebProxy proxyObject = new WebProxy(proxyAddress, true);
proxyObject.Credentials = new NetworkCredential(user, password);
WebRequest req = WebRequest.Create(url);
req.Proxy = proxyObject;
WebResponse response = req.GetResponse();
objStream= response.GetResponseStream();
StreamReader reader = new StreamReader(objStream);
string text = reader.ReadToEnd();
Console.Write(text);
Console.Read();
Console.ReadKey();
但我想要的是,我想使用我的windows凭据访问该页面。因为在我们公司,我们使用相同的凭据进行web访问。

使用:


我尝试了,但得到错误状态:ProtocolError消息:远程服务器返回错误:(407)代理身份验证required@user2983359代码的上下文是什么?这是在IIS中运行的GUI应用程序还是代码?代码运行的用户上下文是什么?现在我只是尝试访问控制台应用程序中的页面。@user2983359和控制台应用程序运行的用户与您使用硬编码凭据的用户相同?给定的url是什么?是,控制台应用程序在同一用户下运行。
proxyObject.Credentials = CredentialCache.DefaultCredentials;