C# C访问少数网站时Webclient超时
我可以在windows 7 pc上使用webclient访问所有网页, 相同的代码在windows server 2008 R2上不起作用 下面是一个示例网站:在win7中使用webclient可以正常工作,但在2008 R2服务器中无法工作 以下是我使用的代码片段:C# C访问少数网站时Webclient超时,c#,visual-studio-2010,webclient,connection-timeout,C#,Visual Studio 2010,Webclient,Connection Timeout,我可以在windows 7 pc上使用webclient访问所有网页, 相同的代码在windows server 2008 R2上不起作用 下面是一个示例网站:在win7中使用webclient可以正常工作,但在2008 R2服务器中无法工作 以下是我使用的代码片段: using (WebClient client = new WebClient()) { client.Headers["User-Agent"] = "Mozilla/4.0 (Compatible; Windo
using (WebClient client = new WebClient())
{
client.Headers["User-Agent"] =
"Mozilla/4.0 (Compatible; Windows NT 5.1; MSIE 6.0) " +
"(compatible; MSIE 6.0; Windows NT 5.1; " +
".NET CLR 1.1.4322; .NET CLR 2.0.50727)";
// Download data.
byte[] arr = client.DownloadData("https://www.euronext.com/");
// Write values.
Console.WriteLine("--- WebClient result ---");
Console.WriteLine(arr.Length);
}
我也尝试了以下代码:
WebClient client = new WebClient();
// Set user agent and also accept-encoding headers.
client.Headers["User-Agent"] =
"Googlebot/2.1 (+http://www.googlebot.com/bot.html)";
client.Headers["Accept-Encoding"] = "gzip";
// Download data.
byte[] arr = client.DownloadData("https://www.euronext.com/");
// Get response header.
string contentEncoding = client.ResponseHeaders["Content-Encoding"];
// Write values.
Console.WriteLine("--- WebClient result ---");
Console.WriteLine(arr.Length);
Console.WriteLine(contentEncoding);
如果我在这里误会了什么,有人能指引我吗
谢谢你的期待
问候,,
沙雷斯
例外情况详细信息
System.Net.WebException:基础连接已关闭:发送时发生意外错误。-->System.IO.IOException:从传输流接收到意外的EOF或0字节。在System.Net.TlsStream.EndWriteIAsyncResult asyncResult System.Net.ConnectStream.WriteHeadersCallbackIAsyncResult内部异常堆栈跟踪的ar端System.Net.HttpWebRequest.EndGetResponseAsyncResult asyncResult System.Net.WebClient.GetWebResponseWebRequest请求中,IAsyncResult结果位于CapitalIQ.WebCrawler.Lib.CookieAwareWebClient.GetWebResponseWebRequest请求,IAsyncResult结果位于C:\myProject\MsHtml\Classes\WebClient\CookieAwareWebClient.cs:System.Net.WebClient.OpenReadAsyncCallbackIAsyncResult结果的第62行此外,我还尝试了以下代码。发布您得到的异常,可能还有堆栈跟踪。您可以从服务器浏览到该网站吗?有些服务器有防火墙规则,可以防止出站互联网流量。泰德·尼伯格:是的,我可以从服务器访问网站。在浏览器中一切看起来都很好。我已在我的查询中附加了异常