Geeks With Blogs

News My Blog has been MOVED to
Michael Freidgeim's OLD Blog My Blog has been MOVED to
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 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 =
           webRequest.CookieContainer = cntnrCookies;
webRequest.Timeout = ConfigurationExtensions.GetAppSetting("HttpWebRequest.Timeout", 100000);
//default 100sec-
           /*                //try to change - from          
                       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:
Posted on Friday, June 15, 2012 9:56 PM ASP.NET | Back to top

Comments on this post: Configuration setting of HttpWebRequest.Timeout value

No comments posted yet.
Your comment:
 (will show your gravatar)

Copyright © Michael Freidgeim | Powered by: