17

これらの設定を検出/再利用することは可能ですか?

どのように ?

私が得ている例外は、これは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"
4

4 に答える 4

25

HttpWebRequest は、デフォルトで IE プロキシ設定を実際に使用します。

それらを使用したくない場合は、.Proxy プロパティを 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();
于 2009-07-20T19:21:05.160 に答える
3

これを ISA サーバーでうまく動作させるのに問題がある場合は、次の方法でプロキシを設定してみてください。

IWebProxy webProxy = WebRequest.DefaultWebProxy;
webProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
myRequest.Proxy = webProxy;
于 2013-06-28T14:23:36.487 に答える
1

WebRequest.Proxy が明示的に設定されていない場合 (デフォルトでは に設定されています)、これはデフォルトで発生しますWebRequest.DefaultWebProxy

于 2009-07-20T19:19:06.677 に答える