如果不打开 Fiddler,为什么在下载页面时会出现 SocketException?

Why I get SocketException when downloading a page if I don't open Fiddler?

我遇到了一个奇怪的问题 situation.I 有一种方法可以下载如下页面:

public static bool DownloadPageContent(string url, 
                                       out string content,  
                                       ref int statusCode, 
                                       CookieContainer cookie = null, 
                                       int maxAttempt = 1, 
                                       Encoding encoding = null)
{
      int i = 0;
      using (var client = new CookieAwareWebClient())
      {
            if (encoding != null)
                client.Encoding = encoding;

            while (i < maxAttempt)
            {
                try
                {
                      i++;
                      if (cookie != null) 
                           client.CookieContainer = cookie;
                      client.Headers.Add("user-agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko");
                      content = client.DownloadString(url);
                      statusCode = 200;
                      return true;
                 }
                 catch(WebException ex)
                 {    
                       /* some error handling code*/
                        _logger.Log(LogLevel.Error, ex);

                  }
                  catch (Exception ex)
                  {
                       _logger.Log(LogLevel.Error, ex);
                  }
            }
            content = "";
            return false;
}

这是 StackTrace,它发生在 content = client.DownloadString(url) 行:

System.Net.WebException: Can't connect to remote server ---> System.Net.Sockets.SocketException: An attempt was made to access a socket in a way forbidden by its access permissions xxx.xxx.xxx:80] System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) +208ı xxx.xxx.xxx:80 konum: System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) konum: System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- İç özel durum yığını izlemesinin sonu --- konum: System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request) konum: System.Net.WebClient.DownloadString(Uri address) konum: System.Net.WebClient.DownloadString(String address) konum: Kokoshome_Product_Downloader.Helpers.SiteHelpers.DownloadPageContent(String url, String& content, Int32& statusCode, CookieContainer cookie, Int32 maxAttempt, Encoding encoding)

奇怪的是,如果我打开 Fiddler2 和 运行 程序,它运行良好!这段代码曾经有效,我已经使用 Fiddler 一段时间了,据我所知我没有更改任何 options.But 现在有问题,我无法弄清楚。那么可能是什么问题?

注意:我的互联网没有其他问题 connection.I 可以在没有 Fiddler 的情况下连接互联网。我的操作系统是 Windows 8.1.

更新

当我尝试连接 MySQL 数据库和 FTP server.And 时,我遇到了同样的异常,但 Fiddler 也不起作用。我做了一些研究,并在 Windows Sockets Error Codes

中找到了有关错误的信息

WSAEACCES 10013

Permission denied. An attempt was made to access a socket in a way forbidden by its access permissions. An example is using a broadcast address for sendto without broadcast permission being set using setsockopt(SO_BROADCAST). Another possible reason for the WSAEACCES error is that when the bind function is called (on Windows NT 4.0 with SP4 and later), another application, service, or kernel mode driver is bound to the same address with exclusive access. Such exclusive access is a new feature of Windows NT 4.0 with SP4 and later, and is implemented by using the SO_EXCLUSIVEADDRUSE option.

但我仍然不知道如何修复它。

在几乎所有情况下,这意味着您的防火墙正在阻止您的程序访问网络。当你使用 Fiddler 时,请求在去往 Fiddler 的途中会绕过防火墙,然后绕过防火墙,因为你有一个允许 Fiddler 访问 Internet 的防火墙豁免。