HttpWebRequest’s Timeout and ReadWriteTimeout — What do these mean for the underlying TCP connection?

This problem has been debated on another question, see Adjusting HttpWebRequest Connection Timeout in C#. The discussion made my head spin, so I’ll offer my summary. Although, MSDN explains that the HttpWebRequest.Timeout Property applies to HttpWebRequest.GetResponse and HttpWebRequest.GetRequestStream calls, the description is a bit confusing. Jim Mischel is more helpful: Timeout “is the time for … Read more

HttpWebRequest.GetResponse throws WebException on HTTP 304

Ok, this seems to be a by-design behavior and a perfect example of a vexing exception. This can be solved with this: public static HttpWebResponse GetHttpResponse(this HttpWebRequest request) { try { return (HttpWebResponse) request.GetResponse(); } catch (WebException ex) { if(ex.Response == null || ex.Status != WebExceptionStatus.ProtocolError) throw; return (HttpWebResponse)ex.Response; } }

HttpWebRequest.GetResponse() keeps getting timed out

I had the very same issue. For me the fix was as simple as wrapping the HttpWebResponse code in using block. using (HttpWebResponse response = (HttpWebResponse) request.GetResponse()) { // Do your processings here…. } Details: This issue usually happens when several requests are made to the same host, and WebResponse is not disposed properly. That … Read more

C# – Connection: keep-alive Header is Not Being Sent During HttpWebRequest

I’ve had the same issue: The Connection: Keep-Alive header is not sent except the first request, and the server I accessed won’t give me the correct response if it is missing. So, here are my workarounds to this issue: First is set the ProtocolVersion property of HttpWebRequest instance to HttpVersion.Version10. Except the http command will … Read more

reading HttpwebResponse json response, C#

First you need an object public class MyObject { public string Id {get;set;} public string Text {get;set;} … } Then in here using (var twitpicResponse = (HttpWebResponse)request.GetResponse()) { using (var reader = new StreamReader(twitpicResponse.GetResponseStream())) { JavaScriptSerializer js = new JavaScriptSerializer(); var objText = reader.ReadToEnd(); MyObject myojb = (MyObject)js.Deserialize(objText,typeof(MyObject)); } } I haven’t tested with the … Read more

HttpWebResponse.Cookies empty despite Set-Cookie Header (no-redirect)

UPDATE five years later, someone actually mentioned the correct way to do it: setting up the CookieContainer correctly in the first place and letting it handle everything. Please refer to Sam’s solution further down. I’ve found that issue as well, when reading Cookies in C# that were created by a C# ASP.NET app… 😉 Not … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)