gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 04:53:49 25 4
gpt4 key购买 nike

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

如何?

我遇到的异常是这是连接到 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 属性覆盖为 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();

关于c# - 如何在 .net HttpWebRequest 中自动检测/使用 IE 代理设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1155363/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com