慢WebClient.DownloadString? [英] Slow WebClient.DownloadString?
问题描述
我的工作是与ASP.Net 3.5上运行的Web应用程序
I'm working on a web application that runs with ASP.Net 3.5
在某处的应用,我正在给外部系统调用。这一呼吁包括从特定的URL下载的字符串:
Somewhere in the application, I'm making calls to an external system. This call consists on downloading a string from a specific url :
string targetUrl = BuildMyUrl();
WebClient wc = new WebClient();
string data = wc.DownloadString(targetUrl);
此代码工作得很好用可接受的响应时间(500毫秒以下)。
This code works quite well with a acceptable response time (under 500ms).
然而,在特定情况下,这种反应时间超过15秒。我可以重现的行为,我可以清楚的看到很长一段时间是在 DownloadString
电话。
However, in specific cases this response time is over 15 seconds. I can reproduce the behavior, and I can clearly see the long time is on the DownloadString
call.
的
I don't understand why this occurs in my scenario.
您会说:嘿,这是目标系统,慢行。但我不能能够重现我的应用程序之外的行为(我建立一个隔离断层代码小型控制台应用程序。从来没有得到任何问题)。
You will say : "Hey, it's the target system that is slow". But I was not able able to reproduce the behavior outside my application (I've build a small console application that isolate the faulting code. Never get any issue).
我不知道去哪里现在看明白这个问题。哪些原因会导致一个简单的下载数据进行很长
I don't know where to look now to understand the issue. What can cause a simple download data to be be lengthy ?
FYI:目标系统是一种身份验证服务。目标URL是怎么样的:
FYI: the target system is an authentication service. The target url is of kind :
HTTP 取值:// mysystem /验证票= XXXYYY
httpS://mysystem/validate?ticket=XXXYYY
也许https协议是问题。
Maybe the https protocol is the issue.
是否使用IIS下WebClient类?可以改变Web客户端的行为
Does using WebClient class under IIS can alter the behavior of the WebClient ?
我已经试过:
- 要明确设置WebClient的对象的
代理
属性设置为null -
我已经换成了DownloadData通话这段代码:
- To explicitly set the
Proxy
property of the WebClient object to null I've replaced the DownloadData call by this code :
VAR REQ =(HttpWebRequest的)WebRequest.CreateDefault(新的URI(targetUrl这个));使用
(VAR响应=(HttpWebResponse)req.GetResponse())
{
使用(VAR SR =新的StreamReader(response.GetResponseStream()))
{
数据= sr.ReadToEnd();
}
}
var req = (HttpWebRequest)WebRequest.CreateDefault(new Uri(targetUrl)); using (var response = (HttpWebResponse)req.GetResponse()) { using (var sr = new StreamReader(response.GetResponseStream())) { data= sr.ReadToEnd(); } }
本次测试没有成功。
推荐答案
的延迟是由于证书验证超时。一链中的发行者的不正确部署在客户端服务器
The latency was due to a certificate validation timeout. One of the issuer in the chain was not correctly deployed in the client server.
这篇关于慢WebClient.DownloadString?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!