ASP.Net延迟,如何判断是客户端还是服务器端?
我在网站上有一个通用处理程序。当我直接访问它时,它会立即响应。当我尝试从 .Net 程序访问它时,在服务器注册请求之前有一个很长的(10 秒的给予或接受)暂停。
这是我用来访问服务器的代码:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://MYURL/fs.ashx");
request.Method = "POST";
request.ContentType = "text/xml";
// This is the line that takes 10 seconds to return
StreamWriter streamOut = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(sXMLToSend);
streamOut.Close();
XmlDocument doc = new XmlDocument();
HttpWebResponse resp = null;
resp = (HttpWebResponse)request.GetResponse();
StreamReader responseReader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);
sResponse = responseReader.ReadToEnd();
Console.WriteLine(sResponse);
resp.Close();
我不认为这条线在大约一周前花费了那么长时间,但我没有任何数据来支持这一点。有什么想法可能是什么问题吗?如果我在浏览器中点击该网址,它会立即响应。是否有任何工具可以用来确定它是我的机器,还是服务器,或者......我什至不知道从哪里开始。
I've got a generic handler on a site. When I go directly to it it responds immediately. When I try to get to it from a .Net program, there is a long (10 second give or take) pause before the server is registering the request.
Here is the code I'm using to hit the server:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://MYURL/fs.ashx");
request.Method = "POST";
request.ContentType = "text/xml";
// This is the line that takes 10 seconds to return
StreamWriter streamOut = new StreamWriter(request.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(sXMLToSend);
streamOut.Close();
XmlDocument doc = new XmlDocument();
HttpWebResponse resp = null;
resp = (HttpWebResponse)request.GetResponse();
StreamReader responseReader = new StreamReader(resp.GetResponseStream(), Encoding.UTF8);
sResponse = responseReader.ReadToEnd();
Console.WriteLine(sResponse);
resp.Close();
I don't think that this line was taking that long about a week ago, but I don't have any data to back that up. Any ideas what the issue could be? If I hit the url in a browser it responds immediately. Are there any tools that I can use to figure out if it is my machine, or the server, or...I don't even know where to begin.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
可能只是因为 GetRequestStream 是一个同步方法并且它在返回之前将其全部缓冲起来?也许您应该尝试调用异步版本并在数据传入时对其进行处理。
Might it just be due to the fact that GetRequestStream is a synchronous method and its buffering it all up before returning? Maybe you should try calling the async version and process data as it comes in.