HttpWebResponse response = (HttpWebResponse)request.GetResponse();这句话求教

xuxujian 2008-11-08 06:15:34
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

这个经常出现不成功的状况,是网络太差了

求教怎么处理一下,让他错误时自动重试呢?谢谢了
...全文
308 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuxujian 2008-11-08
  • 打赏
  • 举报
回复
谢谢
  • 打赏
  • 举报
回复
Timeout 设置长点看看

HttpWebRequest httpWReq = (HttpWebRequest)HttpWebRequest.Create(url);
httpWReq.KeepAlive = false;
httpWReq.AllowAutoRedirect = true;
httpWReq.Timeout =60000; //ms
httpWReq.ContentType = "application/x-www-form-urlencoded";

HttpWebResponse httpWResp = (HttpWebResponse)httpWReq.GetResponse();

byte[] buffer = new byte[httpWResp.ContentLength+200];
Stream outstream = httpWResp.GetResponseStream();
int count = outstream.Read(buffer, 0, buffer.Length);
string rtnstring = System.Text.UTF8Encoding.UTF8.GetString(buffer, 0, count);
return rtnstring;
这是本人经常使用的。

111,119

社区成员

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

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

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