{"id":856,"date":"2021-04-10T17:21:29","date_gmt":"2021-04-10T08:21:29","guid":{"rendered":"https:\/\/todosoft.net\/blog\/?p=856"},"modified":"2021-04-10T17:21:30","modified_gmt":"2021-04-10T08:21:30","slug":"post-856","status":"publish","type":"post","link":"https:\/\/todosoft.net\/blog\/?p=856","title":{"rendered":"\u6587\u5b57\u30b3\u30fc\u30c9\u3092\u8003\u616e\u3057\u3066WebClient\u3067\u30b5\u30a4\u30c8\u30bd\u30fc\u30b9\u3092\u53d6\u5f97\u3059\u308b"},"content":{"rendered":"\n<pre class=\"wp-block-luxe-blocks-syntaxhighlighter line-numbers language-csharp\"><code class=\"language-csharp\">private async Task&lt;string> GetSiteSource(string url, Uri reffrrer = null)\n{\n    using (System.Net.WebClient objWebClient = new System.Net.WebClient())\n    {\n        if(reffrrer != null)\n            objWebClient.Headers.Add(HttpRequestHeader.Referer, reffrrer.ToString());\n\n        objWebClient.Headers.Add(HttpRequestHeader.UserAgent, strUserAgent);\n        objWebClient.Encoding = System.Text.Encoding.UTF8;\n        string strSource = await objWebClient.DownloadStringTaskAsync(url);\n\n        ContentType contentType = new ContentType(objWebClient.ResponseHeaders[\"Content-Type\"]);\n\n        switch(contentType.CharSet.ToLower().Replace(\"-\", \"\"))\n        {\n            case \"utf8\":\n                break;\n\n            case \"eucjp\":\n                objWebClient.Encoding = System.Text.Encoding.GetEncoding(\"euc-jp\");\n                strSource = await objWebClient.DownloadStringTaskAsync(url);\n                break;\n\n            case \"shiftjis\":\n                objWebClient.Encoding = System.Text.Encoding.GetEncoding(\"shift-jis\");\n                strSource = await objWebClient.DownloadStringTaskAsync(url);\n                break;\n\n            default:\n                break;\n        }\n\n        return strSource;\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[19,15],"tags":[104,103],"class_list":["post-856","post","type-post","status-publish","format-standard","hentry","category-c","category-15","tag-encoding","tag-webclient"],"_links":{"self":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/856","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=856"}],"version-history":[{"count":1,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/856\/revisions"}],"predecessor-version":[{"id":857,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=\/wp\/v2\/posts\/856\/revisions\/857"}],"wp:attachment":[{"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=856"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=856"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/todosoft.net\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=856"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}