我想连接到http网页,但每次进入catch并返回错误远程服务器(407)需要代理身份验证。为什么?我在另一个网站项目中使用了相同的代码,但它确实有效。
WebProxy wp = new WebProxy("**");
wp.Credentials = new NetworkCredential("**", "**");
StringBuilder sbXmlText = new StringBuilder();
try
{
WebClient MyWebClient = new WebClient();
MyWebClient.Proxy = wp;
Stream TheStream = MyWebClient.OpenRead("http://www.bnr.ro/nbrfxrates10days.xml");
StreamReader TheStreamReader = new StreamReader(TheStream);
while (!TheStreamReader.EndOfStream)
sbXmlText.Append((char)TheStreamReader.Read());
}
catch (Exception ex)
{
mail_send_bnr(ex.ToString(), "Error on connecting to bnr", "test");
}