Configuration setting of HttpWebRequest.Timeout value
Posted
by Michael Freidgeim
on Geeks with Blogs
See other posts from Geeks with Blogs
or by Michael Freidgeim
Published on Fri, 15 Jun 2012 10:56:43 GMT
Indexed on
2012/06/15
15:17 UTC
Read the original article
Hit count: 634
Filed under:
I wanted to set in configuration on client HttpWebRequest.Timeout.
I was surprised, that MS doesn’t provide it as a part of .Net configuration.
(Answer in http://forums.silverlight.net/post/77818.aspx thread: “Unfortunately specifying the timeout is not supported in current version. We may support it in the future release.”)
I was surprised, that MS doesn’t provide it as a part of .Net configuration.
(Answer in http://forums.silverlight.net/post/77818.aspx thread: “Unfortunately specifying the timeout is not supported in current version. We may support it in the future release.”)
I added it to appSettings section of app.config and read it in the method of My HttpWebRequestHelper class
//The Method property can be set to any of the HTTP 1.1 protocol verbs: GET, HEAD, POST, PUT, DELETE, TRACE, or OPTIONS.
public static HttpWebRequest PrepareWebRequest(string sUrl, string Method, CookieContainer cntnrCookies)
{
HttpWebRequest webRequest = WebRequest.Create(sUrl) as HttpWebRequest;
webRequest.Method = Method;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.CookieContainer = cntnrCookies;
webRequest.Timeout = ConfigurationExtensions.GetAppSetting("HttpWebRequest.Timeout", 100000);
//default 100sec-http://blogs.msdn.com/b/buckh/archive/2005/02/01/365127.aspx)
/* //try to change - from http://www.codeproject.com/csharp/ClientTicket_MSNP9.asp
webRequest.AllowAutoRedirect = false;
webRequest.Pipelined = false;
webRequest.KeepAlive = false;
webRequest.ProtocolVersion = new Version(1,0);//protocol 1.0 works better that 1.1 ??
*/
//MNF 26/5/2005 Some web servers expect UserAgent to be specified
//so let's say it's IE6
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
DebugOutputHelper.PrintHttpWebRequest(webRequest, TraceOutputHelper.LineWithTrace(""));
return webRequest;
}
Related link:
http://stackoverflow.com/questions/387247/i-need-help-setting-net-httpwebrequest-timeout
v //The Method property can be set to any of the HTTP 1.1 protocol verbs: GET, HEAD, POST, PUT, DELETE, TRACE, or OPTIONS.
public static HttpWebRequest PrepareWebRequest(string sUrl, string Method, CookieContainer cntnrCookies)
{
HttpWebRequest webRequest = WebRequest.Create(sUrl) as HttpWebRequest;
webRequest.Method = Method;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.CookieContainer = cntnrCookies;
webRequest.Timeout = ConfigurationExtensions.GetAppSetting("HttpWebRequest.Timeout", 100000);
//default 100sec-http://blogs.msdn.com/b/buckh/archive/2005/02/01/365127.aspx)
/* //try to change - from http://www.codeproject.com/csharp/ClientTicket_MSNP9.asp
webRequest.AllowAutoRedirect = false;
webRequest.Pipelined = false;
webRequest.KeepAlive = false;
webRequest.ProtocolVersion = new Version(1,0);//protocol 1.0 works better that 1.1 ??
*/
//MNF 26/5/2005 Some web servers expect UserAgent to be specified
//so let's say it's IE6
webRequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET CLR 1.1.4322)";
DebugOutputHelper.PrintHttpWebRequest(webRequest, TraceOutputHelper.LineWithTrace(""));
return webRequest;
}
Related link:
http://stackoverflow.com/questions/387247/i-need-help-setting-net-httpwebrequest-timeout
© Geeks with Blogs or respective owner