{"id":47548,"date":"2024-10-07T14:41:17","date_gmt":"2024-10-07T06:41:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/47548\/"},"modified":"2024-10-07T14:41:17","modified_gmt":"2024-10-07T06:41:17","slug":"iis%e6%96%b0%e6%89%8b%e6%8c%87%e5%8d%97%ef%bc%9a%e4%bd%bf%e7%94%a8iis%e7%ae%a1%e7%90%86api","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/47548\/","title":{"rendered":"IIS\u65b0\u624b\u6307\u5357\uff1a\u4f7f\u7528IIS\u7ba1\u7406API"},"content":{"rendered":"<h1 id=\"iis%e6%96%b0%e6%89%8b%e6%8c%87%e5%8d%97%ef%bc%9a%e4%bd%bf%e7%94%a8iis%e7%ae%a1%e7%90%86api-XrWwWeskub\">IIS\u65b0\u624b\u6307\u5357\uff1a\u4f7f\u7528IIS\u7ba1\u7406API<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0cIIS\uff08Internet Information Services\uff09\u4f5c\u70ba\u5fae\u8edf\u7684\u4e00\u6b3e\u5f37\u5927\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5f0f\u7684\u90e8\u7f72\u3002\u5c0d\u65bc\u65b0\u624b\u4f86\u8aaa\uff0c\u4e86\u89e3\u5982\u4f55\u4f7f\u7528IIS\u7ba1\u7406API\u662f\u4e00\u500b\u91cd\u8981\u7684\u6b65\u9a5f\uff0c\u56e0\u70ba\u9019\u53ef\u4ee5\u5e6b\u52a9\u4ed6\u5011\u66f4\u6709\u6548\u5730\u7ba1\u7406\u548c\u914d\u7f6e\u4f3a\u670d\u5668\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afiis%e7%ae%a1%e7%90%86api%ef%bc%9f-XrWwWeskub\">\u4ec0\u9ebc\u662fIIS\u7ba1\u7406API\uff1f<\/h2>\n<p>IIS\u7ba1\u7406API\u662f\u4e00\u7d44\u7528\u65bc\u7ba1\u7406IIS\u4f3a\u670d\u5668\u7684RESTful API\u3002\u9019\u4e9bAPI\u5141\u8a31\u958b\u767c\u8005\u548c\u7cfb\u7d71\u7ba1\u7406\u54e1\u901a\u904e\u7a0b\u5f0f\u5316\u7684\u65b9\u5f0f\u4f86\u57f7\u884c\u5404\u7a2e\u64cd\u4f5c\uff0c\u4f8b\u5982\u5275\u5efa\u7db2\u7ad9\u3001\u914d\u7f6e\u61c9\u7528\u7a0b\u5f0f\u6c60\u3001\u7ba1\u7406\u5b89\u5168\u6027\u8a2d\u7f6e\u7b49\u3002\u9019\u7a2e\u65b9\u5f0f\u4e0d\u50c5\u63d0\u9ad8\u4e86\u7ba1\u7406\u7684\u9748\u6d3b\u6027\uff0c\u9084\u80fd\u5920\u81ea\u52d5\u5316\u8a31\u591a\u91cd\u8907\u6027\u7684\u4efb\u52d9\u3002<\/p>\n<h2 id=\"%e5%a6%82%e4%bd%95%e9%96%8b%e5%a7%8b%e4%bd%bf%e7%94%a8iis%e7%ae%a1%e7%90%86api-XrWwWeskub\">\u5982\u4f55\u958b\u59cb\u4f7f\u7528IIS\u7ba1\u7406API<\/h2>\n<p>\u5728\u958b\u59cb\u4f7f\u7528IIS\u7ba1\u7406API\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u5df2\u7d93\u5b89\u88dd\u4e86IIS\u4e26\u555f\u7528\u4e86\u7ba1\u7406API\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<ul>\n<li>\u78ba\u4fdd\u60a8\u7684\u4f3a\u670d\u5668\u4e0a\u5df2\u5b89\u88ddIIS\u3002<\/li>\n<li>\u5728IIS\u7ba1\u7406\u5668\u4e2d\uff0c\u555f\u7528\u201c\u7ba1\u7406API\u201d\u529f\u80fd\u3002<\/li>\n<li>\u78ba\u4fdd\u60a8\u7684\u61c9\u7528\u7a0b\u5f0f\u5177\u6709\u9069\u7576\u7684\u6b0a\u9650\u4f86\u8a2a\u554fAPI\u3002<\/li>\n<\/ul>\n<h3 id=\"%e5%9f%ba%e6%9c%ac%e7%9a%84api%e8%ab%8b%e6%b1%82-XrWwWeskub\">\u57fa\u672c\u7684API\u8acb\u6c42<\/h3>\n<p>\u4f7f\u7528IIS\u7ba1\u7406API\u6642\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528HTTP\u8acb\u6c42\u4f86\u8207\u4f3a\u670d\u5668\u9032\u884c\u4ea4\u4e92\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528C#\u7684\u7c21\u55ae\u7bc4\u4f8b\uff0c\u5c55\u793a\u5982\u4f55\u767c\u9001GET\u8acb\u6c42\u4ee5\u7372\u53d6\u4f3a\u670d\u5668\u4e0a\u7684\u7db2\u7ad9\u5217\u8868\uff1a<\/p>\n<pre><code>\nusing System;\nusing System.Net.Http;\nusing System.Threading.Tasks;\n\nclass Program\n{\n    static async Task Main()\n    {\n        using (HttpClient client = new HttpClient())\n        {\n            client.BaseAddress = new Uri(\"http:\/\/localhost:8080\/\");\n            HttpResponseMessage response = await client.GetAsync(\"api\/websites\");\n            if (response.IsSuccessStatusCode)\n            {\n                string result = await response.Content.ReadAsStringAsync();\n                Console.WriteLine(result);\n            }\n        }\n    }\n}\n<\/code><\/pre>\n<h2 id=\"%e5%b8%b8%e8%a6%8b%e7%9a%84api%e6%93%8d%e4%bd%9c-XrWwWeskub\">\u5e38\u898b\u7684API\u64cd\u4f5c<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684IIS\u7ba1\u7406API\u64cd\u4f5c\uff1a<\/p>\n<ul>\n<li><strong>\u5275\u5efa\u7db2\u7ad9\uff1a<\/strong>\u4f7f\u7528POST\u8acb\u6c42\u4f86\u5275\u5efa\u65b0\u7684\u7db2\u7ad9\u3002<\/li>\n<li><strong>\u522a\u9664\u7db2\u7ad9\uff1a<\/strong>\u4f7f\u7528DELETE\u8acb\u6c42\u4f86\u522a\u9664\u73fe\u6709\u7db2\u7ad9\u3002<\/li>\n<li><strong>\u66f4\u65b0\u7db2\u7ad9\u8a2d\u7f6e\uff1a<\/strong>\u4f7f\u7528PUT\u8acb\u6c42\u4f86\u66f4\u65b0\u7db2\u7ad9\u7684\u914d\u7f6e\u3002<\/li>\n<\/ul>\n<h3 id=\"%e5%89%b5%e5%bb%ba%e7%b6%b2%e7%ab%99%e7%9a%84%e7%af%84%e4%be%8b-XrWwWeskub\">\u5275\u5efa\u7db2\u7ad9\u7684\u7bc4\u4f8b<\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b\u5275\u5efa\u7db2\u7ad9\u7684\u7bc4\u4f8b\uff0c\u4f7f\u7528POST\u8acb\u6c42\u4f86\u6dfb\u52a0\u4e00\u500b\u65b0\u7db2\u7ad9\uff1a<\/p>\n<pre><code>\nusing System;\nusing System.Net.Http;\nusing System.Text;\nusing System.Threading.Tasks;\n\nclass Program\n{\n    static async Task Main()\n    {\n        using (HttpClient client = new HttpClient())\n        {\n            client.BaseAddress = new Uri(\"http:\/\/localhost:8080\/\");\n            var content = new StringContent(\"{\"name\":\"MyNewSite\",\"physicalPath\":\"C:\\inetpub\\wwwroot\\MyNewSite\"}\", Encoding.UTF8, \"application\/json\");\n            HttpResponseMessage response = await client.PostAsync(\"api\/websites\", content);\n            if (response.IsSuccessStatusCode)\n            {\n                Console.WriteLine(\"\u7db2\u7ad9\u5275\u5efa\u6210\u529f\uff01\");\n            }\n        }\n    }\n}\n<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e5%85%a8%e6%80%a7%e8%80%83%e9%87%8f-XrWwWeskub\">\u5b89\u5168\u6027\u8003\u91cf<\/h2>\n<p>\u5728\u4f7f\u7528IIS\u7ba1\u7406API\u6642\uff0c\u5b89\u5168\u6027\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u78ba\u4fdd\u60a8\u4f7f\u7528HTTPS\u4f86\u52a0\u5bc6\u50b3\u8f38\uff0c\u4e26\u4e14\u5c0dAPI\u7684\u8a2a\u554f\u9032\u884c\u8eab\u4efd\u9a57\u8b49\u548c\u6388\u6b0a\u3002\u6b64\u5916\uff0c\u5b9a\u671f\u6aa2\u67e5\u548c\u66f4\u65b0API\u7684\u6b0a\u9650\u8a2d\u7f6e\uff0c\u4ee5\u9632\u6b62\u672a\u7d93\u6388\u6b0a\u7684\u8a2a\u554f\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-XrWwWeskub\">\u7e3d\u7d50<\/h2>\n<p>\u4f7f\u7528IIS\u7ba1\u7406API\u53ef\u4ee5\u5927\u5927\u63d0\u9ad8\u4f3a\u670d\u5668\u7ba1\u7406\u7684\u6548\u7387\uff0c\u7279\u5225\u662f\u5c0d\u65bc\u9700\u8981\u81ea\u52d5\u5316\u548c\u6279\u91cf\u64cd\u4f5c\u7684\u60c5\u6cc1\u3002\u900f\u904e\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528\u9019\u4e9bAPI\uff0c\u60a8\u53ef\u4ee5\u66f4\u9748\u6d3b\u5730\u7ba1\u7406\u60a8\u7684IIS\u4f3a\u670d\u5668\uff0c\u4e26\u63d0\u5347\u6574\u9ad4\u7684\u904b\u71df\u6548\u7387\u3002\u5982\u679c\u60a8\u6b63\u5728\u5c0b\u627e\u53ef\u9760\u7684\u4f3a\u670d\u5668\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u6216<a href=\"https:\/\/server.hk\">\u9999\u6e2f\u4f3a\u670d\u5668<\/a>\u4f86\u652f\u6301\u60a8\u7684\u696d\u52d9\u9700\u6c42\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22IIS\u65b0\u624b\u6307\u5357\uff0c\u5b66\u4e60\u5982\u4f55\u4f7f\u7528IIS\u7ba1\u7406API\u8fdb\u884c\u7f51\u7ad9\u7ba1\u7406\u548c\u914d\u7f6e\uff0c\u63d0\u5347\u4f60\u7684Web\u5f00\u53d1\u6280\u80fd\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-47548","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/47548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=47548"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/47548\/revisions"}],"predecessor-version":[{"id":47549,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/47548\/revisions\/47549"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=47548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=47548"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=47548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}