如何访问代理后面的页面

时间:2017-03-06 15:09:03

标签: 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 = 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访问。

1 个答案:

答案 0 :(得分:0)

使用CredentialCache.DefaultCredentials

proxyObject.Credentials = CredentialCache.DefaultCredentials;