下面是一个网站示例,当我从本地开发环境请求时返回ok,但是当从生产服务器请求时,请求在15秒后超时。请求标头完全相同。有什么想法吗?
http://www.dealsdirect.com.au/p/wall-mounted-fish-tank-30cm/
答案 0 :(得分:1)
这里有一件事我想指出我已经提供的其他东西。当您调用GetResponse
时,必须尽快处理返回的对象。否则会发生停顿,或者下一次调用将阻塞并可能超时,因为System.Net.
// The request doesn't matter, it's not holding on to any critical resources
var request = (HttpWebRequest)WebRequest.Create(url);
// The response however is, these will eventually be reclaimed by the GC
// but you'll run into problems similar to deadlocks if you don't dispose them yourself
// when you have many of them
using (var response = request.GetResponse())
{
// Do stuff with `response` here
}
如果不了解具体细节,这个问题很难回答。没有理由说IIS会像这样表现,这让我得出结论,问题与你应用程序正在做的事情有关,但我对此一无所知。如果您可以使用附加的调试器重现问题,您可能能够找到问题发生的位置,但如果您不能先执行此操作,那么我无能为力。
您是否在开发中使用ASP.NET Development Server或IIS Express?
如果这是代理的问题,这里是一个工厂方法我用来设置需要代理需要一些身份验证的HTTP请求(但是,我不相信我曾经收到过时间):
HttpWebRequest CreateRequest(Uri url)
{
var request = (HttpWebRequest)WebRequest.Create(url);
request.Timeout = 120 * 1000;
request.CookieContainer = _cookieContainer;
if (UseSystemWebProxy)
{
var proxy = WebRequest.GetSystemWebProxy();
if (UseDefaultCredentials)
{
proxy.Credentials = CredentialCache.DefaultCredentials;
}
if (UseNetworkCredentials != null
&& UseNetworkCredentials.Length > 0)
{
var networkCredential = new NetworkCredential();
networkCredential.UserName = UseNetworkCredentials[0];
if (UseNetworkCredentials.Length > 1)
{
networkCredential.Password = UseNetworkCredentials[1];
}
if (UseNetworkCredentials.Length > 2)
{
networkCredential.Domain = UseNetworkCredentials[2];
}
proxy.Credentials = networkCredential;
}
request.Proxy = proxy;
}
return request;
}
试试Adrian并让我知道它是怎么回事。