如何在 .net HttpWebRequest 中自动检测/使用 IE 代理设置 [英] How to AutoDetect/Use IE proxy settings in .net HttpWebRequest

查看:31
本文介绍了如何在 .net HttpWebRequest 中自动检测/使用 IE 代理设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to detect/reuse those settings ?

怎么样?

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

The exception i'm getting is This is the exception while connecting to 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 代理设置.

HttpWebRequest will actually use the IE proxy settings by default.

如果您不想使用它们,您必须专门将 .Proxy 属性覆盖为 null(无代理)或您选择的代理设置.

If you don't want to use them, you have to specifically override the .Proxy proprty to either null (no proxy), or the proxy settings of you choice.

 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();

这篇关于如何在 .net HttpWebRequest 中自动检测/使用 IE 代理设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆