{"id":1450,"date":"2014-02-18T19:46:01","date_gmt":"2014-02-18T19:46:01","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=1450"},"modified":"2014-02-19T09:34:06","modified_gmt":"2014-02-19T09:34:06","slug":"c-code-for-accessing-the-network-through-a-proxy-server","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/c-code-for-accessing-the-network-through-a-proxy-server\/","title":{"rendered":"C# code for accessing the network through a proxy server"},"content":{"rendered":"<p><strong>How to setup proxy authentication and details<\/strong><\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nICredentials credentials = CredentialCache.DefaultCredentials;\r\nIWebProxy proxy = new WebProxy(proxyServerHost, proxyServerPort);\r\nproxy.Credentials = credentials;\r\n<\/pre>\n<p>The code (above) creates a set of credentials, in this case we get the user&#8217;s <em>DefaultCredentials<\/em> and ultimately places the credentials into the <em>IWebProxy<\/em>.<\/p>\n<p>The <em>IWebProxy<\/em> is then instantiated with the host name and the port of the proxy server.<\/p>\n<p><strong>Let&#8217;s use the proxy<\/strong><\/p>\n<p>Now to use the web proxy obviously requires the library\/framework to support proxies. So this is just one example using the .NET WebClient class.<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing (WebClient wc = new WebClient())\r\n{\r\n   if(proxy != null)\r\n   {\r\n      wc.Proxy = proxy;\r\n   }\r\n   byte&#x5B;] data = wc.DownloadData(url);\r\n}\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How to setup proxy authentication and details ICredentials credentials = CredentialCache.DefaultCredentials; IWebProxy proxy = new WebProxy(proxyServerHost, proxyServerPort); proxy.Credentials = credentials; The code (above) creates a set of credentials, in this case we get the user&#8217;s DefaultCredentials and ultimately places the credentials into the IWebProxy. The IWebProxy is then instantiated with the host name and the [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3],"tags":[],"class_list":["post-1450","post","type-post","status-publish","format-standard","hentry","category-c"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/1450","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=1450"}],"version-history":[{"count":4,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/1450\/revisions"}],"predecessor-version":[{"id":1464,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/1450\/revisions\/1464"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=1450"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=1450"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=1450"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}