是否可以检测/重用这些设置?
怎么做到的?
我得到的异常是这是连接到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"
发布于 2013-08-02 17:34:37
我遇到了一个非常类似的情况,在默认情况下,HttpWebRequest没有获取正确的代理详细信息,并且设置UseDefaultCredentials也不起作用。然而,强制代码中的设置起到了很好的效果:
IWebProxy proxy = myWebRequest.Proxy;
if (proxy != null) {
string proxyuri = proxy.GetProxy(myWebRequest.RequestUri).ToString();
myWebRequest.UseDefaultCredentials = true;
myWebRequest.Proxy = new WebProxy(proxyuri, false);
myWebRequest.Proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
}
因为这使用默认凭证,所以不应该向用户询问它们的详细信息。
请注意,这是我在这里发布的一个非常类似问题的答案的副本:Proxy Basic Authentication in C#: HTTP 407 error
发布于 2013-06-28 22:23:36
对于在使用ISA服务器时遇到问题的人,您可以尝试用以下方式设置代理:
IWebProxy webProxy = WebRequest.DefaultWebProxy;
webProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
myRequest.Proxy = webProxy;
发布于 2009-07-20 19:19:07
默认情况下,如果没有显式设置WebRequest.Proxy (默认情况下设置为WebRequest.DefaultWebProxy
),就会发生这种情况。
https://stackoverflow.com/questions/1155363
复制相似问题