{"id":2186,"date":"2015-04-20T08:00:00","date_gmt":"2015-04-20T07:00:00","guid":{"rendered":"http:\/\/www.diogonunes.com\/blog\/?p=2186"},"modified":"2020-05-15T14:23:49","modified_gmt":"2020-05-15T13:23:49","slug":"webclient-vs-httpclient-vs-httpwebrequest","status":"publish","type":"post","link":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/","title":{"rendered":"WebClient vs HttpClient vs HttpWebRequest"},"content":{"rendered":"<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?resize=510%2C350\" alt=\"restless\" width=\"510\" height=\"350\" class=\"aligncenter size-full wp-image-2199\" srcset=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?w=510&amp;ssl=1 510w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?resize=400%2C275&amp;ssl=1 400w\" sizes=\"auto, (max-width: 510px) 100vw, 510px\" \/><\/p>\n<p><!--more--><\/p>\n<p>Just when I was starting to get used to call WebServices through WSDL &#8211; like I showed <a href=\"http:\/\/www.diogonunes.com\/blog\/calling-a-web-method-in-c-without-a-service-reference\/\">here<\/a> and <a href=\"http:\/\/www.diogonunes.com\/blog\/calling-webservice-without-wsdl-or-web-reference\/\">here<\/a> &#8211; I had to call a RESTful API. If you don&#8217;t know what I&#8217;m talking about you&#8217;re like me <a href=\"http:\/\/stackoverflow.com\/a\/840713\/675577\">a week ago<\/a>. Let&#8217;s just say that:<\/p>\n<ul>\n<li>a <strong>WSDL<\/strong> API uses <strong>SOAP<\/strong> to exchange <strong>XML<\/strong>-encoded data<\/li>\n<li>a <strong>REST<\/strong> API uses <strong>HTTP<\/strong> to exchange <strong>JSON<\/strong>-encoded data<\/li>\n<\/ul>\n<p>That&#8217;s a whole new paradigm. Instead of <code>GetObject()<\/code> and <code>SetObject()<\/code> methods you have a single url <code>api\/object<\/code> that may receive either an <code>HTTP GET<\/code> request or an <code>HTTP POST<\/code> request.<\/p>\n<p>The .NET framework offers you three different classes to consume REST APIs: <code>HttpWebRequest<\/code>, <code>WebClient<\/code>, <code>HttpClient<\/code>. To worsen your <a href=\"http:\/\/en.wikipedia.org\/wiki\/Analysis_paralysis\">analysis paralysis<\/a> the open-source community created yet another library called <code>RestSharp<\/code>. Fear not, I&#8217;ll ease your choice.<\/p>\n<h3>In the beginning there was&#8230; HttpWebRequest<\/h3>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/d41339a1ca4823cf39fa29453d41d073186851f2a09f0b07513024e1af43ebc8-400x296.jpg?resize=400%2C296\" alt=\"d41339a1ca4823cf39fa29453d41d073186851f2a09f0b07513024e1af43ebc8\" width=\"400\" height=\"296\" class=\"aligncenter size-medium wp-image-2192\" srcset=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/d41339a1ca4823cf39fa29453d41d073186851f2a09f0b07513024e1af43ebc8.jpg?resize=400%2C296&amp;ssl=1 400w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/d41339a1ca4823cf39fa29453d41d073186851f2a09f0b07513024e1af43ebc8.jpg?w=560&amp;ssl=1 560w\" sizes=\"auto, (max-width: 400px) 100vw, 400px\" \/><\/p>\n<p>This is the standard class that the .NET creators originally developed to consume HTTP requests. Using <code>HttpWebRequest<\/code> <a href=\"http:\/\/stackoverflow.com\/a\/8237452\/675577\">gives you control<\/a> over every aspect of the request\/response object, like timeouts, cookies, headers, protocols. Another great thing is that <code>HttpWebRequest<\/code> class does not block the user interface thread. For instance, while you&#8217;re downloading a big file from a sluggish API server, your application&#8217;s UI will remain responsive.<\/p>\n<p>However, <strong>with great power comes great complexity.<\/strong> In order to make a simple <code>GET<\/code> you need at least five lines of code; we will see that <code>WebClient<\/code> uses just two lines.<\/p>\n<pre><code>HttpWebRequest http = (HttpWebRequest)WebRequest.Create(\"http:\/\/example.com\");\nWebResponse response = http.GetResponse();\n\nMemoryStream stream = response.GetResponseStream();\nStreamReader sr = new StreamReader(stream);\nstring content = sr.ReadToEnd();\n<\/code><\/pre>\n<p>The number of ways you can make a mistake with <code>HttpWebRequest<\/code> is truly astounding. Only use <code>HttpWebRequest<\/code> if you require the additional low-level control that it offers.<\/p>\n<h3>WebClient. Simple.<\/h3>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/for_dummies_plain-1024x528.png?resize=580%2C299\" alt=\"for_dummies_plain\" width=\"580\" height=\"299\" class=\"aligncenter size-large wp-image-2196\" srcset=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/for_dummies_plain.png?resize=1024%2C528&amp;ssl=1 1024w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/for_dummies_plain.png?resize=400%2C206&amp;ssl=1 400w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/for_dummies_plain.png?resize=1272%2C656&amp;ssl=1 1272w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/for_dummies_plain.png?w=1386&amp;ssl=1 1386w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/for_dummies_plain.png?w=1160&amp;ssl=1 1160w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/p>\n<p><code>WebClient<\/code> is a higher-level abstraction built on top of <code>HttpWebRequest<\/code> to <a href=\"http:\/\/stackoverflow.com\/a\/22792326\/675577\"><strong>simplify the most common tasks<\/strong><\/a>. Using <code>WebClient<\/code> is potentially slower (on the order of a few milliseconds) than using <code>HttpWebRequest<\/code> directly. But that &#8220;inefficiency&#8221; comes with huge benefits: it requires <a href=\"http:\/\/www.c-sharpcorner.com\/uploadfile\/dhananjaycoder\/webclient-and-httpwebrequest-class\/\">less code<\/a>, is easier to use, and you&#8217;re less likely to make a mistake when using it. That same request example is now as simple as:<\/p>\n<pre><code>var client = new WebClient();\nvar text = client.DownloadString(\"http:\/\/example.com\/page.html\");\n<\/code><\/pre>\n<p><em>Note: the using statements from both examples were omitted for brevity. You should definitely dispose your web request objects properly.<\/em><\/p>\n<p>Don&#8217;t worry, you can still specify timeouts, just make sure you <a href=\"http:\/\/stackoverflow.com\/questions\/601861\/set-timeout-for-webclient-downloadfile\/3052637#3052637\">follow this workaround<\/a>.<\/p>\n<h3>HttpClient, the best of both worlds<\/h3>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/httpclient.jpg?resize=580%2C440\" alt=\"httpclient\" width=\"580\" height=\"440\" class=\"aligncenter size-full wp-image-2194\" srcset=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/httpclient.jpg?w=643&amp;ssl=1 643w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/httpclient.jpg?resize=400%2C304&amp;ssl=1 400w\" sizes=\"auto, (max-width: 580px) 100vw, 580px\" \/><\/p>\n<p><code>HttpClient<\/code> provides powerful functionality with better syntax support for newer threading features, e.g. it supports the <code>await<\/code> keyword. It also enables threaded downloads of files with better compiler checking and code validation. For a complete listing of the advantages and features of this class make sure you read <a href=\"http:\/\/stackoverflow.com\/a\/27737601\/675577\">this SO answer<\/a>.<\/p>\n<p>The only downfall is that it requires .NET Framework 4.5, which many older or legacy machines might not have.<\/p>\n<h3>Wait, a new contestant has appeared!<\/h3>\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/RestSharp_logo.png?resize=461%2C120\" alt=\"RestSharp_logo\" width=\"461\" height=\"120\" class=\"aligncenter size-full wp-image-2198\" srcset=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/RestSharp_logo.png?w=461&amp;ssl=1 461w, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/RestSharp_logo.png?resize=400%2C104&amp;ssl=1 400w\" sizes=\"auto, (max-width: 461px) 100vw, 461px\" \/><\/p>\n<p>Since <code>HttpClient<\/code> is only available for the .NET 4.5 platform the community developed an alternative. Today, <a href=\"http:\/\/restsharp.org\/\"><code>RestSharp<\/code><\/a> is one of the only options for a portable, multi-platform, unencumbered, fully open-source HTTP client that you can use in all of your applications.<\/p>\n<p>It combines the control of <code>HttpWebRequest<\/code> with the simplicity of <code>WebClient<\/code>.<\/p>\n<h3>Conclusion<\/h3>\n<ul>\n<li><code>HttpWebRequest<\/code> for control<\/li>\n<li><code>WebClient<\/code> for simplicity and brevity<\/li>\n<li><code>RestSharp<\/code> for both on non-.NET 4.5 environments<\/li>\n<li><code>HttpClient<\/code> for both + async features on .NET 4.5 environments<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":2199,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[2],"tags":[47,29,22,48],"class_list":["post-2186","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-tech","tag-c-sharp","tag-coding","tag-review","tag-web-dev"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.6 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>WebClient vs HttpClient vs HttpWebRequest - The Geeky Gecko<\/title>\n<meta name=\"description\" content=\"What&#039;s the best way to call a REST API on C#? I&#039;ll review the 4 main classes (RestSharp included) to make requests and process their responses.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"WebClient vs HttpClient vs HttpWebRequest - The Geeky Gecko\" \/>\n<meta property=\"og:description\" content=\"What&#039;s the best way to call a REST API on C#? I&#039;ll review the 4 main classes (RestSharp included) to make requests and process their responses.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/\" \/>\n<meta property=\"og:site_name\" content=\"The Geeky Gecko\" \/>\n<meta property=\"article:published_time\" content=\"2015-04-20T07:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2020-05-15T13:23:49+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1\" \/>\n\t<meta property=\"og:image:width\" content=\"510\" \/>\n\t<meta property=\"og:image:height\" content=\"350\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Diogo Nunes\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@dialexnunes\" \/>\n<meta name=\"twitter:site\" content=\"@dialexnunes\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Diogo Nunes\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/\"},\"author\":{\"name\":\"Diogo Nunes\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c\"},\"headline\":\"WebClient vs HttpClient vs HttpWebRequest\",\"datePublished\":\"2015-04-20T07:00:00+00:00\",\"dateModified\":\"2020-05-15T13:23:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/\"},\"wordCount\":503,\"publisher\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c\"},\"image\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1\",\"keywords\":[\"c#\",\"coding\",\"review\",\"web dev\"],\"articleSection\":[\"Technology\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/\",\"url\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/\",\"name\":\"WebClient vs HttpClient vs HttpWebRequest - The Geeky Gecko\",\"isPartOf\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1\",\"datePublished\":\"2015-04-20T07:00:00+00:00\",\"dateModified\":\"2020-05-15T13:23:49+00:00\",\"description\":\"What's the best way to call a REST API on C#? I'll review the 4 main classes (RestSharp included) to make requests and process their responses.\",\"breadcrumb\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#primaryimage\",\"url\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1\",\"width\":510,\"height\":350},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.diogonunes.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WebClient vs HttpClient vs HttpWebRequest\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#website\",\"url\":\"https:\/\/www.diogonunes.com\/blog\/\",\"name\":\"The Geeky Gecko\",\"description\":\"The Geeky Gecko\",\"publisher\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.diogonunes.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c\",\"name\":\"Diogo Nunes\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2026\/04\/Geeky-Gecko-2026-v2.png?fit=799%2C799&ssl=1\",\"contentUrl\":\"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2026\/04\/Geeky-Gecko-2026-v2.png?fit=799%2C799&ssl=1\",\"width\":799,\"height\":799,\"caption\":\"Diogo Nunes\"},\"logo\":{\"@id\":\"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/www.diogonunes.com\",\"https:\/\/x.com\/dialexnunes\"],\"url\":\"https:\/\/www.diogonunes.com\/blog\/author\/diogo-nunes\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"WebClient vs HttpClient vs HttpWebRequest - The Geeky Gecko","description":"What's the best way to call a REST API on C#? I'll review the 4 main classes (RestSharp included) to make requests and process their responses.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/","og_locale":"en_US","og_type":"article","og_title":"WebClient vs HttpClient vs HttpWebRequest - The Geeky Gecko","og_description":"What's the best way to call a REST API on C#? I'll review the 4 main classes (RestSharp included) to make requests and process their responses.","og_url":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/","og_site_name":"The Geeky Gecko","article_published_time":"2015-04-20T07:00:00+00:00","article_modified_time":"2020-05-15T13:23:49+00:00","og_image":[{"width":510,"height":350,"url":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1","type":"image\/png"}],"author":"Diogo Nunes","twitter_card":"summary_large_image","twitter_creator":"@dialexnunes","twitter_site":"@dialexnunes","twitter_misc":{"Written by":"Diogo Nunes","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#article","isPartOf":{"@id":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/"},"author":{"name":"Diogo Nunes","@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c"},"headline":"WebClient vs HttpClient vs HttpWebRequest","datePublished":"2015-04-20T07:00:00+00:00","dateModified":"2020-05-15T13:23:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/"},"wordCount":503,"publisher":{"@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c"},"image":{"@id":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1","keywords":["c#","coding","review","web dev"],"articleSection":["Technology"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/","url":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/","name":"WebClient vs HttpClient vs HttpWebRequest - The Geeky Gecko","isPartOf":{"@id":"https:\/\/www.diogonunes.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#primaryimage"},"image":{"@id":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1","datePublished":"2015-04-20T07:00:00+00:00","dateModified":"2020-05-15T13:23:49+00:00","description":"What's the best way to call a REST API on C#? I'll review the 4 main classes (RestSharp included) to make requests and process their responses.","breadcrumb":{"@id":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#primaryimage","url":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1","width":510,"height":350},{"@type":"BreadcrumbList","@id":"https:\/\/www.diogonunes.com\/blog\/webclient-vs-httpclient-vs-httpwebrequest\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.diogonunes.com\/blog\/"},{"@type":"ListItem","position":2,"name":"WebClient vs HttpClient vs HttpWebRequest"}]},{"@type":"WebSite","@id":"https:\/\/www.diogonunes.com\/blog\/#website","url":"https:\/\/www.diogonunes.com\/blog\/","name":"The Geeky Gecko","description":"The Geeky Gecko","publisher":{"@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.diogonunes.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/a6fa79b293f22912664654fcfbd2da0c","name":"Diogo Nunes","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2026\/04\/Geeky-Gecko-2026-v2.png?fit=799%2C799&ssl=1","contentUrl":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2026\/04\/Geeky-Gecko-2026-v2.png?fit=799%2C799&ssl=1","width":799,"height":799,"caption":"Diogo Nunes"},"logo":{"@id":"https:\/\/www.diogonunes.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/www.diogonunes.com","https:\/\/x.com\/dialexnunes"],"url":"https:\/\/www.diogonunes.com\/blog\/author\/diogo-nunes\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2015\/04\/restless.png?fit=510%2C350&ssl=1","jetpack-related-posts":[{"id":1451,"url":"https:\/\/www.diogonunes.com\/blog\/calling-webservice-without-wsdl-or-web-reference\/","url_meta":{"origin":2186,"position":0},"title":"Calling Web Service without WSDL or Web Reference","author":"Diogo Nunes","date":"17 November, 2014","format":false,"excerpt":"Once I had to test in C# a dozen of web services developed by a third-party. However they provided no WSDL and no ASMX - therefore it would be impossible to use Web References. They only provided the name of the web methods, their urls, calling credentials and an XML\u2026","rel":"","context":"In &quot;Technology&quot;","block_context":{"text":"Technology","link":"https:\/\/www.diogonunes.com\/blog\/category\/tech\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2014\/11\/77043.jpg?fit=675%2C450&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2014\/11\/77043.jpg?fit=675%2C450&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2014\/11\/77043.jpg?fit=675%2C450&ssl=1&resize=525%2C300 1.5x"},"classes":[]},{"id":1486,"url":"https:\/\/www.diogonunes.com\/blog\/calling-a-web-method-in-c-without-a-service-reference\/","url_meta":{"origin":2186,"position":1},"title":"Calling a Web Method in C# without Service Reference","author":"Diogo Nunes","date":"24 November, 2014","format":false,"excerpt":"Last week I gave you a method that, using SOAP and HttpWebRequest, allowed you to invoke a Web Method without a WSDL or a Web Reference. Well today, I'll give you an improved version of that method. In fact I'll give you a whole ready-to-use class with additional functionality. Recapping,\u2026","rel":"","context":"In &quot;Technology&quot;","block_context":{"text":"Technology","link":"https:\/\/www.diogonunes.com\/blog\/category\/tech\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2014\/11\/This-is-a-SOAP-request.png?fit=506%2C350&ssl=1&resize=350%2C200","width":350,"height":200},"classes":[]},{"id":4569,"url":"https:\/\/www.diogonunes.com\/blog\/lean-contract-testing-with-chakram\/","url_meta":{"origin":2186,"position":2},"title":"Lean contract testing with Chakram","author":"Diogo Nunes","date":"17 October, 2022","format":false,"excerpt":"\ud83c\udfc6 This post was featured in Software Testing Weekly #142 and CodingJab #111 During my career, every time my team has to rely on a 3rd-party API, there comes the day where that API fails. Maybe it is down but usually they released a breaking change that breaks the previous\u2026","rel":"","context":"In &quot;Technology&quot;","block_context":{"text":"Technology","link":"https:\/\/www.diogonunes.com\/blog\/category\/tech\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2022\/10\/cytonn-photography-n95VMLxqM2I-unsplash-1.jpg?fit=1200%2C801&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2022\/10\/cytonn-photography-n95VMLxqM2I-unsplash-1.jpg?fit=1200%2C801&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2022\/10\/cytonn-photography-n95VMLxqM2I-unsplash-1.jpg?fit=1200%2C801&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2022\/10\/cytonn-photography-n95VMLxqM2I-unsplash-1.jpg?fit=1200%2C801&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2022\/10\/cytonn-photography-n95VMLxqM2I-unsplash-1.jpg?fit=1200%2C801&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":3955,"url":"https:\/\/www.diogonunes.com\/blog\/framework-review-karate\/","url_meta":{"origin":2186,"position":3},"title":"Framework review: Karate","author":"Diogo Nunes","date":"2 November, 2020","format":false,"excerpt":"Karate is the only open-source tool to combine API test-automation, mocks, performance-testing and even UI automation into a single, unified framework. You don't have to compile (Java) code. Just write tests in a readable syntax. \u2014 Official website Code Example of automation at GitHub. Use cases \ud83e\udd47 Automate API tests.\u2026","rel":"","context":"In &quot;Technology&quot;","block_context":{"text":"Technology","link":"https:\/\/www.diogonunes.com\/blog\/category\/tech\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2020\/08\/thao-le-hoang-igLzPKOvZNw-unsplash-scaled.jpg?fit=1200%2C798&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2020\/08\/thao-le-hoang-igLzPKOvZNw-unsplash-scaled.jpg?fit=1200%2C798&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2020\/08\/thao-le-hoang-igLzPKOvZNw-unsplash-scaled.jpg?fit=1200%2C798&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2020\/08\/thao-le-hoang-igLzPKOvZNw-unsplash-scaled.jpg?fit=1200%2C798&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2020\/08\/thao-le-hoang-igLzPKOvZNw-unsplash-scaled.jpg?fit=1200%2C798&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":4038,"url":"https:\/\/www.diogonunes.com\/blog\/monitor-psi-pagespeed-google-sheets\/","url_meta":{"origin":2186,"position":4},"title":"Monitor PageSpeed (v5) with Google Sheets","author":"Diogo Nunes","date":"21 June, 2021","format":false,"excerpt":"The goal is to create a Google Sheet that can track the historical PageSpeed Insights (PSI) perfomance data of one or more pages\/URLs. You will use JavaScript code to call the PageSpeed Insights API and store the result in your sheet. Run the test + Store the data For each\u2026","rel":"","context":"In &quot;Technology&quot;","block_context":{"text":"Technology","link":"https:\/\/www.diogonunes.com\/blog\/category\/tech\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2020\/10\/Screenshot_2020-08-26_at_15.40.55.png?fit=1200%2C580&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2020\/10\/Screenshot_2020-08-26_at_15.40.55.png?fit=1200%2C580&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2020\/10\/Screenshot_2020-08-26_at_15.40.55.png?fit=1200%2C580&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2020\/10\/Screenshot_2020-08-26_at_15.40.55.png?fit=1200%2C580&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2020\/10\/Screenshot_2020-08-26_at_15.40.55.png?fit=1200%2C580&ssl=1&resize=1050%2C600 3x"},"classes":[]},{"id":4204,"url":"https:\/\/www.diogonunes.com\/blog\/framework-review-playwright\/","url_meta":{"origin":2186,"position":5},"title":"Framework review: Playwright","author":"Diogo Nunes","date":"29 March, 2021","format":false,"excerpt":"Playwright enables end-to-end testing. Test modern single page apps, across all modern browsers, using in your preferred language (JS, TS, Java, C#, Python). \u2014 Official website Code Example of automation at GitHub. Use cases \ud83e\udd48 Automate end-to-end (E2E) tests using the UI. It also supports mocks. Learning curve \ud83e\udd48 Most\u2026","rel":"","context":"In &quot;Technology&quot;","block_context":{"text":"Technology","link":"https:\/\/www.diogonunes.com\/blog\/category\/tech\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/03\/fatih-kilic-m1dM7ZXvdMs-unsplash.jpg?fit=1200%2C773&ssl=1&resize=350%2C200","width":350,"height":200,"srcset":"https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/03\/fatih-kilic-m1dM7ZXvdMs-unsplash.jpg?fit=1200%2C773&ssl=1&resize=350%2C200 1x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/03\/fatih-kilic-m1dM7ZXvdMs-unsplash.jpg?fit=1200%2C773&ssl=1&resize=525%2C300 1.5x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/03\/fatih-kilic-m1dM7ZXvdMs-unsplash.jpg?fit=1200%2C773&ssl=1&resize=700%2C400 2x, https:\/\/i0.wp.com\/www.diogonunes.com\/blog\/wp-content\/uploads\/2021\/03\/fatih-kilic-m1dM7ZXvdMs-unsplash.jpg?fit=1200%2C773&ssl=1&resize=1050%2C600 3x"},"classes":[]}],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/posts\/2186","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/comments?post=2186"}],"version-history":[{"count":1,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/posts\/2186\/revisions"}],"predecessor-version":[{"id":3188,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/posts\/2186\/revisions\/3188"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/media\/2199"}],"wp:attachment":[{"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/media?parent=2186"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/categories?post=2186"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.diogonunes.com\/blog\/wp-json\/wp\/v2\/tags?post=2186"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}