<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: Unifying HTTP success and failure in .NET</title>
	<atom:link href="http://blog.jonudell.net/2009/01/22/unifying-http-success-and-failure-in-net/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.jonudell.net/2009/01/22/unifying-http-success-and-failure-in-net/</link>
	<description>Strategies for Internet citizens</description>
	<lastBuildDate>Sun, 12 Feb 2012 18:22:41 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: remove google redirect virus</title>
		<link>http://blog.jonudell.net/2009/01/22/unifying-http-success-and-failure-in-net/#comment-184086</link>
		<dc:creator><![CDATA[remove google redirect virus]]></dc:creator>
		<pubDate>Sun, 18 Sep 2011 01:26:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jonudell.net/?p=1086#comment-184086</guid>
		<description><![CDATA[&lt;strong&gt;remove google redirect virus 2011...&lt;/strong&gt;

[...]Unifying HTTP success and failure in .NET &#171; Jon Udell[...]...]]></description>
		<content:encoded><![CDATA[<p><strong>remove google redirect virus 2011&#8230;</strong></p>
<p>[...]Unifying HTTP success and failure in .NET &laquo; Jon Udell[...]&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: New York Snow</title>
		<link>http://blog.jonudell.net/2009/01/22/unifying-http-success-and-failure-in-net/#comment-183750</link>
		<dc:creator><![CDATA[New York Snow]]></dc:creator>
		<pubDate>Fri, 16 Sep 2011 00:57:05 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jonudell.net/?p=1086#comment-183750</guid>
		<description><![CDATA[&lt;strong&gt;New York Snow...&lt;/strong&gt;

[...]Unifying HTTP success and failure in .NET &#171; Jon Udell[...]...]]></description>
		<content:encoded><![CDATA[<p><strong>New York Snow&#8230;</strong></p>
<p>[...]Unifying HTTP success and failure in .NET &laquo; Jon Udell[...]&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ako Help Desk</title>
		<link>http://blog.jonudell.net/2009/01/22/unifying-http-success-and-failure-in-net/#comment-183635</link>
		<dc:creator><![CDATA[Ako Help Desk]]></dc:creator>
		<pubDate>Thu, 15 Sep 2011 04:12:19 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jonudell.net/?p=1086#comment-183635</guid>
		<description><![CDATA[&lt;strong&gt;Ako Help Desk...&lt;/strong&gt;

[...]Unifying HTTP success and failure in .NET &#171; Jon Udell[...]...]]></description>
		<content:encoded><![CDATA[<p><strong>Ako Help Desk&#8230;</strong></p>
<p>[...]Unifying HTTP success and failure in .NET &laquo; Jon Udell[...]&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jon Udell</title>
		<link>http://blog.jonudell.net/2009/01/22/unifying-http-success-and-failure-in-net/#comment-126760</link>
		<dc:creator><![CDATA[Jon Udell]]></dc:creator>
		<pubDate>Tue, 17 Feb 2009 20:16:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jonudell.net/?p=1086#comment-126760</guid>
		<description><![CDATA[&gt; I’m sorry for being blunt

No worries, I am very green in C# and don&#039;t pretend otherwise.

&gt; in naming convention 

What do you prefer and why?

&gt; and in what it actually does

FWIW, this wrapper isn&#039;t just a way to guarantee a response, but also to package up everything for downstream inspection -- not just in a debugger but, frequently, from an IronPython client. 

&gt; you can even build this as a sexy 
&gt; extension method

Very nice. Thanks!]]></description>
		<content:encoded><![CDATA[<p>&gt; I’m sorry for being blunt</p>
<p>No worries, I am very green in C# and don&#8217;t pretend otherwise.</p>
<p>&gt; in naming convention </p>
<p>What do you prefer and why?</p>
<p>&gt; and in what it actually does</p>
<p>FWIW, this wrapper isn&#8217;t just a way to guarantee a response, but also to package up everything for downstream inspection &#8212; not just in a debugger but, frequently, from an IronPython client. </p>
<p>&gt; you can even build this as a sexy<br />
&gt; extension method</p>
<p>Very nice. Thanks!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Asbjørn Ulsberg</title>
		<link>http://blog.jonudell.net/2009/01/22/unifying-http-success-and-failure-in-net/#comment-126757</link>
		<dc:creator><![CDATA[Asbjørn Ulsberg]]></dc:creator>
		<pubDate>Tue, 17 Feb 2009 13:55:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jonudell.net/?p=1086#comment-126757</guid>
		<description><![CDATA[I&#039;m sorry for being blunt, but that&#039;s some really nasty C# code you&#039;ve got there. Both in naming convention and in what it actually does. &lt;a href=&quot;#comment-126568&quot; rel=&quot;nofollow&quot;&gt;tamberg&lt;/a&gt; nailed it. Just catch WebException and return its Response property. With .NET 3.5 you can even build this as a sexy extension method on the HttpWebRequest class like this:

public static class HttpWebRequestExtensions {
  public static HttpWebResponse GetResponse(this HttpWebRequest request) {
    HttpWebResponse result;

    try {
      result = request.GetResponse() as HttpWebResponse;
    } catch (WebException ex) {
      result = ex.Response as HttpWebResponse;
    }

    return result;
  }
}

to invoke the extension method, just do the following:

HttpWebResponse response = request.GetResponse();

I completely agree that it&#039;s moronic of the HttpWebRequest class to throw exceptions when the status code is above or equal to 400. At least, it should be configurable. As an example, &quot;410 Gone&quot; is, after all, not an exception, but an expected response that can and should be handled gracefully.

A simple switch(response.StatusCode) is the best way to handle all possible status codes and It&#039;s really painful that Microsoft won&#039;t allow this out of the box.

PS: Comment preview would have been awesome.]]></description>
		<content:encoded><![CDATA[<p>I&#8217;m sorry for being blunt, but that&#8217;s some really nasty C# code you&#8217;ve got there. Both in naming convention and in what it actually does. <a href="#comment-126568" rel="nofollow">tamberg</a> nailed it. Just catch WebException and return its Response property. With .NET 3.5 you can even build this as a sexy extension method on the HttpWebRequest class like this:</p>
<p>public static class HttpWebRequestExtensions {<br />
  public static HttpWebResponse GetResponse(this HttpWebRequest request) {<br />
    HttpWebResponse result;</p>
<p>    try {<br />
      result = request.GetResponse() as HttpWebResponse;<br />
    } catch (WebException ex) {<br />
      result = ex.Response as HttpWebResponse;<br />
    }</p>
<p>    return result;<br />
  }<br />
}</p>
<p>to invoke the extension method, just do the following:</p>
<p>HttpWebResponse response = request.GetResponse();</p>
<p>I completely agree that it&#8217;s moronic of the HttpWebRequest class to throw exceptions when the status code is above or equal to 400. At least, it should be configurable. As an example, &#8220;410 Gone&#8221; is, after all, not an exception, but an expected response that can and should be handled gracefully.</p>
<p>A simple switch(response.StatusCode) is the best way to handle all possible status codes and It&#8217;s really painful that Microsoft won&#8217;t allow this out of the box.</p>
<p>PS: Comment preview would have been awesome.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: tamberg</title>
		<link>http://blog.jonudell.net/2009/01/22/unifying-http-success-and-failure-in-net/#comment-126568</link>
		<dc:creator><![CDATA[tamberg]]></dc:creator>
		<pubDate>Thu, 22 Jan 2009 17:43:53 +0000</pubDate>
		<guid isPermaLink="false">http://blog.jonudell.net/?p=1086#comment-126568</guid>
		<description><![CDATA[Hi,

to mitigate the status problem we use something like (sorry if the markup&#039;s broken):


static HttpWebResponse GetHttpWebResponse (HttpWebRequest r) {
    HttpWebResponse result;
    try {
        result = r.GetResponse() as HttpWebResponse;
    } catch (WebException e) {
        if (e.Response is HttpWebResponse) {
            result = e.Response as HttpWebResponse;
        } else {
            result = null;
        }
    }
    return result;
}


(you still have to test for null, though)

Regards,
tamberg]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>to mitigate the status problem we use something like (sorry if the markup&#8217;s broken):</p>
<p>static HttpWebResponse GetHttpWebResponse (HttpWebRequest r) {<br />
    HttpWebResponse result;<br />
    try {<br />
        result = r.GetResponse() as HttpWebResponse;<br />
    } catch (WebException e) {<br />
        if (e.Response is HttpWebResponse) {<br />
            result = e.Response as HttpWebResponse;<br />
        } else {<br />
            result = null;<br />
        }<br />
    }<br />
    return result;<br />
}</p>
<p>(you still have to test for null, though)</p>
<p>Regards,<br />
tamberg</p>
]]></content:encoded>
	</item>
</channel>
</rss>

