0

我正在尝试在共享托管环境中使用 HtmlAgilityPack.Load 来解析网页。但是,由于 Web 主机阻止连接,我的生产页面上出现 system.net.sockets.socketexception 错误。

我在尝试使用 Ebay Developer .Net 库时也遇到了同样的问题

有没有其他选择(除了不同的主机或专用服务器)我也尝试过 WebClient 和 HttpWebRequest。

HttpWebRequest 代码

HttpWebRequest oReq = (HttpWebRequest)WebRequest.Create(url);
resp = (HttpWebResponse)oReq.GetResponse();
Encoding encode = System.Text.Encoding.GetEncoding("utf-8");
readStream = new StreamReader(resp.GetResponseStream(), encode);
htmlDoc.LoadHtml(readStream.ReadToEnd());                            

HttpWebRequest 的错误消息

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 xxx.xxx.xxx.xxx:80 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetResponse()

谢谢

4

0 回答 0