首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在.net HttpWebRequest中自动检测/使用IE代理设置

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

Stack Overflow用户
提问于 2009-07-20 19:14:33
回答 3查看 42.4K关注 0票数 17

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

怎么做到的?

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

代码语言:javascript
复制
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"
EN

回答 3

Stack Overflow用户

发布于 2013-08-02 17:34:37

我遇到了一个非常类似的情况,在默认情况下,HttpWebRequest没有获取正确的代理详细信息,并且设置UseDefaultCredentials也不起作用。然而,强制代码中的设置起到了很好的效果:

代码语言:javascript
复制
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

票数 8
EN

Stack Overflow用户

发布于 2013-06-28 22:23:36

对于在使用ISA服务器时遇到问题的人,您可以尝试用以下方式设置代理:

代码语言:javascript
复制
IWebProxy webProxy = WebRequest.DefaultWebProxy;
webProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
myRequest.Proxy = webProxy;
票数 3
EN

Stack Overflow用户

发布于 2009-07-20 19:19:07

默认情况下,如果没有显式设置WebRequest.Proxy (默认情况下设置为WebRequest.DefaultWebProxy),就会发生这种情况。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1155363

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档