首页 新闻 赞助 找找看

在windows服务中 使用 HttpWebRequest发送请求,总是超时(我没分了)

0
[已关闭问题] 关闭于 2016-03-16 14:44

目前做的东西

需要在 windows服务中 使用 HttpWebRequest发起HTTP请求获取一些数据

但是在 windows服务中发请求总是无故的超时

而浏览器中直接访问的话,看快就能获取响应数据

 

KeepAlive 设置成 true /false 都试了

Timeout设置成很大的值也试了

System.Net.ServicePointManager.DefaultConnectionLimit = 200; 也试了

但是就是超时

----------------------

是不是 windows服务里就不能使用 HttpWebRequest 呢 ?

又遇到同样问题,或者知道其中玄机的 大大吗?给指条明路吧,,跪谢(我没分了)

问题补充:

HttpWebRequest request = null;
HttpWebResponse res = null;

 

try
{

  string urll = "http://192.168.154.128:8082/office/tttttestWebService.asp";

  request = (HttpWebRequest)HttpWebRequest.Create(urll);


  //request.Timeout = 10000;
  //request.Headers.Add("apikey", "e60cf7b16e8a609a2f38c82bf733d597");
  //request.Method = "GET";
  //request.KeepAlive = false;
  res = (HttpWebResponse)request.GetResponse();

 

  Stream resStream = res.GetResponseStream();
  StreamReader sr = new StreamReader(resStream,Encoding.GetEncoding("gb2312"));

  string data = sr.ReadToEnd();


return data;

 


}
catch (Exception)
{

  throw;
}
finally
{
  if (res!=null)
  {
    res.Close();
    res = null;
  }
  if (request!=null)
  {
    request.Abort();
    request = null;
  }

}

算了的主页 算了 | 初学一级 | 园豆:3
提问于:2016-03-16 10:34
< >
分享
所有回答(1)
0

这里分析的比较全面,你看看

http://blog.csdn.net/linux7985/article/details/46534415

亚洲DotNet首席技师 | 园豆:143 (初学一级) | 2017-12-23 14:06
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册