c# – 如何在.net HttpWebRequest中自动检测/使用IE代理设置

是否可以检测/重用这些设置?

怎么样 ?

我得到的例外是
这是连接到http://www.google.com时的例外

System.Net.WebException: Unable to connect to the remote server --->
  System.Net.Sockets.SocketException: A connection attempt failed because the
  connected party did not properly respond after a period of time, or established
  connection failed because connected host has failed to respond 66.102.1.99:80

  at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, 
     SocketAddress socketAddress)
  at System.Net.Sockets.Socket.InternalConnect(EndPoint remoteEP)
  at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure,
     Socket s4, Socket s6, Socket& socket, IPAddress& address,
     ConnectSocketState state, IAsyncResult asyncResult, Int32 timeout,
     Exception& exception)
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.GetResponse()
  at mvcTest.MvcApplication.Application_Start() in
     C:\\home\\test\\Application1\\Application1\\Program.cs:line 33"
默认情况下,HttpWebRequest将实际使用IE代理设置。

如果您不想使用它们,则必须专门将.Proxy proprty重写为null(无代理)或您选择的代理设置。

 HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://news.bbc.co.uk");
 //request.Proxy = null; // uncomment this to bypass the default (IE) proxy settings
 HttpWebResponse response = (HttpWebResponse)request.GetResponse();

 Console.WriteLine("Done - press return");
 Console.ReadLine();
翻译自:https://stackoverflow.com/questions/1155363/how-to-autodetect-use-ie-proxy-settings-in-net-httpwebrequest

转载注明原文:c# – 如何在.net HttpWebRequest中自动检测/使用IE代理设置