代码如下:
ServicePointManager.DefaultConnectionLimit = 10;
string DataPost = HTMLInfo[0].ToString() + SetpNum;//我要取一个网站的数据,数据是分页的,这里得到参数;
DataPost = DataPost.Replace("&", "&");
ASCIIEncoding myEncoding = new ASCIIEncoding();
byte[] Byte = myEncoding.GetBytes(DataPost);
MyRequest.ContentType = "application/x-www-form-urlencoded";
MyRequest.Method = "post";
MyRequest.ContentLength = DataPost.Length;
Stream NewStream = MyRequest.GetRequestStream();
NewStream.Write(Byte, 0, Byte.Length); HttpWebResponse Response = (HttpWebResponse)MyRequest.GetResponse();//这里有时候会报错;错误类型如下.
The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.请问哪位碰到过这种问题,错误是偶尔出现的,我试了几次,可能如果网速慢的话,容易出现这个错误,50分求解,不够再另给啊...急
ServicePointManager.DefaultConnectionLimit = 10;
string DataPost = HTMLInfo[0].ToString() + SetpNum;//我要取一个网站的数据,数据是分页的,这里得到参数;
DataPost = DataPost.Replace("&", "&");
ASCIIEncoding myEncoding = new ASCIIEncoding();
byte[] Byte = myEncoding.GetBytes(DataPost);
MyRequest.ContentType = "application/x-www-form-urlencoded";
MyRequest.Method = "post";
MyRequest.ContentLength = DataPost.Length;
Stream NewStream = MyRequest.GetRequestStream();
NewStream.Write(Byte, 0, Byte.Length); HttpWebResponse Response = (HttpWebResponse)MyRequest.GetResponse();//这里有时候会报错;错误类型如下.
The underlying connection was closed: A connection that was expected to be kept alive was closed by the server.请问哪位碰到过这种问题,错误是偶尔出现的,我试了几次,可能如果网速慢的话,容易出现这个错误,50分求解,不够再另给啊...急
try
{
connect();
}
catch
{
if(retry<n)
{
connect();
interlock.increment(retry);
}
}
网络连接总会出现各种预期不到的连接错误,许多重连一次就行了,当然要设置重连数,以免死循环
{
if(retry<n)
{
connect();
interlock.increment(retry);
}
else
{
?
}
}
超过重试次数没有处理,当然出错