HttpWebRequest非常慢 [英] HttpWebRequest is very slow

查看:93
本文介绍了HttpWebRequest非常慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从另一个返回图像的处理程序文件中请求一个处理程序文件,当我请求我的 HttpWebRequest 时,它需要更多的时间来获取响应.这是我的代码,请帮忙.

I am requesting a handler file from another handler file that returns an image, when I request my HttpWebRequest it takes more time to get the response. Here is my code, please help.

HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpCookie cookie = context.Request.Cookies["ASP.NET_SessionID"];
Cookie myCookie = new Cookie(cookie.Name, cookie.Value);
myCookie.Domain = url.Host;

request.CookieContainer = new CookieContainer();
request.CookieContainer.Add(myCookie);
request.Timeout = 200000;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
responseStream = response.GetResponseStream();

推荐答案

首先请确保您的请求尽快到达处理程序.如果不是这样,则说明您的网络存在问题.您可以通过日志或调试或所需的任何方式来诊断此问题.使用Fiddler重新发出请求,以便您确切知道何时触发和接收请求.

First make sure that your request is getting to the handler as quickly as possible. If not then it is some issue with your network. You can diagnose this with logs or debugging or whatever way you need. Use Fiddler to re-issue requests so you know exactly when it is fired and received.

如果要访问服务器并且在该处没有任何处理会花费太多时间,请确保在完成写入后刷新并关闭响应流.也可能最好是处理responseStream对象.

If it is getting to the server and no processing on there is taking too much time then make sure that you are flushing and closing the response stream when you are finished writing to it. Also probably best to dispose of the responseStream object.

using(var responseStream = response.GetResponseStream()){
   // write to the sucker

   responseStream.Flush();
   responseStream.Close();
}

NB如果仅在第一个请求上(您的问题/答案有些困惑),请尝试确定在启动Appdomain时到底发生了什么.global.asax中有什么大功能吗?或者它正在做大量的数据库工作?

NB If this is only on the first request (your question/answers are a little confusing) then try work out what exactly is happening at startup of the appdomain. Is there something big in global.asax - or is it doing a lot of DB work?

这篇关于HttpWebRequest非常慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆