public string Post(string url, string content, string referer, Encoding endcode)
{
int failedTimes = _tryTimes;
//endcode = Encoding.UTF8;
while (failedTimes-- > 0)
{
try
{
if (_delayTime > 0)
{
Thread.Sleep(_delayTime * 1000);
}
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(url));
req.CookieContainer = _cc;
req.Referer = referer;
byte[] buff = Encoding.GetEncoding("GB2312").GetBytes(content);
req.Method = "POST";
req.Timeout = _timeout;
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; CIBA)";
//req.CookieContainer = ""; req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = buff.Length;
if (null != _proxy && null != _proxy.Credentials)
{
req.UseDefaultCredentials = true;
}
req.Proxy = _proxy;
//req.Connection = "Keep-Alive"; Stream reqStream = req.GetRequestStream();
reqStream.Write(buff, 0, buff.Length);
reqStream.Close();
//接收返回字串
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
//StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
StreamReader sr = new StreamReader(res.GetResponseStream(), endcode);
return sr.ReadToEnd();
}
catch (Exception e)
{
TraceLog.Error("HTTP POST Error: " + e.Message);
TraceLog.Error("Url: " + url);
TraceLog.Error("Data: " + content);
}
} return string.Empty;
}基本上能POST成功,但是有的时候POST后出现一个这样的异常消息,寻了很久的资料,没找到相应的解决方法:HTTP POST Error: The underlying connection was closed: An unexpected error occurred on a receive.
{
int failedTimes = _tryTimes;
//endcode = Encoding.UTF8;
while (failedTimes-- > 0)
{
try
{
if (_delayTime > 0)
{
Thread.Sleep(_delayTime * 1000);
}
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(new Uri(url));
req.CookieContainer = _cc;
req.Referer = referer;
byte[] buff = Encoding.GetEncoding("GB2312").GetBytes(content);
req.Method = "POST";
req.Timeout = _timeout;
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727; CIBA)";
//req.CookieContainer = ""; req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = buff.Length;
if (null != _proxy && null != _proxy.Credentials)
{
req.UseDefaultCredentials = true;
}
req.Proxy = _proxy;
//req.Connection = "Keep-Alive"; Stream reqStream = req.GetRequestStream();
reqStream.Write(buff, 0, buff.Length);
reqStream.Close();
//接收返回字串
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
//StreamReader sr = new StreamReader(res.GetResponseStream(), Encoding.UTF8);
StreamReader sr = new StreamReader(res.GetResponseStream(), endcode);
return sr.ReadToEnd();
}
catch (Exception e)
{
TraceLog.Error("HTTP POST Error: " + e.Message);
TraceLog.Error("Url: " + url);
TraceLog.Error("Data: " + content);
}
} return string.Empty;
}基本上能POST成功,但是有的时候POST后出现一个这样的异常消息,寻了很久的资料,没找到相应的解决方法:HTTP POST Error: The underlying connection was closed: An unexpected error occurred on a receive.
解决方案 »
- WPF ComboBox绑定集合,并根据集合中每个元素的特征决定是否禁止该项
- WebRequest对象的GetResponse方法一直丢出远程服务器返回错误: (401) 未经授权的异常
- 简单对象和负责对象
- WCF Add Service Reference出错
- 浏览按钮的代码怎么写?在线等,非常急,希望知道的我给我一人答案,,万分感谢
- 求C#无组件上传图片源码
- .NET Framework 中的 Generic 还真是这么回事,
- 可不可以将listView赋予另一个listView(C#)
- 请教:有关Remoting的安全问题
- picturebox已经设置了errorimage,但仍然是大红叉?
- 用c#开发个会员刷卡系统,请高手给点建议或参考的东西
- 请求高手解密下面的编码,这是什么编码的?求解密!
查看
However I finally found a thread in a forum which suggested to modify the rsReportServer.config by changing the value of SecureConnectionLevel from 2 to 0. I had tried and the error is gone.
你那个是SQL数据库的吧~!