一个System.Net.WebException错误,求助

chenfeng432 2010-09-19 04:08:39
网页错误System.Net.WebException: 基础连接已经关闭: 发送时发生错误。 ---> System.IO.IOException: 由于意外的数据包格式,握手失败。 在 System.Net.Security.SslState.StartReadFrame(Byte[] buffer, Int32 readBytes, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.StartReceiveBlob(Byte[] buffer, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.ForceAuthentication(Boolean receiveFirst, Byte[] buffer, AsyncProtocolRequest asyncRequest) 在 System.Net.Security.SslState.ProcessAuthentication(LazyAsyncResult lazyResult) 在 System.Net.TlsStream.CallProcessAuthentication(Object state) 在 System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state) 在 System.Net.TlsStream.ProcessAuthentication(LazyAsyncResult result) 在 System.Net.TlsStream.Write(Byte[] buffer, Int32 offset, Int32 size) 在 System.Net.PooledStream.Write(Byte[] buffer, Int32 offset, Int32 size) 在 System.Net.ConnectStream.WriteHeaders(Boolean async) --- 内部异常堆栈跟踪的结尾 --- 在 System.Net.HttpWebRequest.GetResponse() 在 WindowsFormsApplication1.index.getWebStr(Object road, String seqid, String number) 位置 D:\C#\网页查询\新网页查询\Form1.cs:行号 725



HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.Referer = referer;
request.ContentType = "multipart/form-data";
request.Method = "GET";
request.CookieContainer = cookieContainer[int.Parse(a[2])];
HttpWebResponse response = (HttpWebResponse)request.GetResponse();//725行
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.GetEncoding("gb2312"));
outdata = reader.ReadToEnd();
reader.Close();
stream.Close();
...全文
1084 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
loveSoftandhxy 2010-09-19
  • 打赏
  • 举报
回复
?实在找不到原因的话,就处理下:只要出现问题,重新程序。
或者定时重启。。

这样的问题一般是访问冲突,或者访问一些已经关闭了的资源。

查查看哪些可能的链接。被恶意关闭后,还继续访问的。
chenfeng432 2010-09-19
  • 打赏
  • 举报
回复
我头晕了,我似乎可以在
catch(WebExcption)
{
可以在这里通过检测 e.message 来判断是 400,501 还是:基础连接已经关闭: 发送时发生错误
}
chenfeng432 2010-09-19
  • 打赏
  • 举报
回复
重试没有用的。现在的程序就是这样子,会一直重试,然后就一直抛出一楼的错误。
chenfeng432 2010-09-19
  • 打赏
  • 举报
回复
再问一个问题


我一楼的代码,
然后我
catch(webEcception)
就会得到
System.Net.WebException: 基础连接已经关闭: 发送时发生错误。
System.IO.IOException: 由于意外的数据包格式,握手失败。
我怎么样捕获这个IOException

try
{一楼代码
}
catch(IOExcption)
{
这里捕获不到IOExcption,我现在的思路就是想如果遇到这样错误,就把程序直接停下来。
}
catch(WebExcption)
{
我在这里又不敢直接把程序停下来,因为还有正常的那种 400,或者501错误。
}
兔子-顾问 2010-09-19
  • 打赏
  • 举报
回复
恩。服务器可能认为你访问过频繁了。拒绝很正常。重试即可。
chenfeng432 2010-09-19
  • 打赏
  • 举报
回复
搞了3~4天,根本找不到问题所在,1楼贴出了错误提示的

catch 得出来的。
兔子-顾问 2010-09-19
  • 打赏
  • 举报
回复
出现后拦截异常,再次尝试吧。
chenfeng432 2010-09-19
  • 打赏
  • 举报
回复
出现后就每天都会出现。软件开户,运行大约是2个小时后,时间没具体计算过。然后就是一直出现。直接把窗体关掉,重新打开。
兔子-顾问 2010-09-19
  • 打赏
  • 举报
回复
出现后就每次都出现还是每2小时都出现?一直出现是什么意思?
chenfeng432 2010-09-19
  • 打赏
  • 举报
回复
一般是运行2个小时后会出现这样错误,一直出现。
symbol_bc 2010-09-19
  • 打赏
  • 举报
回复
我测了你的代码,没问题。
兔子-顾问 2010-09-19
  • 打赏
  • 举报
回复
可能服务器拒绝了。偶然一次还是每次都发生?

111,076

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧