{"id":47108,"date":"2024-10-07T11:27:25","date_gmt":"2024-10-07T03:27:25","guid":{"rendered":"https:\/\/server.hk\/cnblog\/47108\/"},"modified":"2024-10-07T11:27:25","modified_gmt":"2024-10-07T03:27:25","slug":"iis%e7%8b%80%e6%85%8b%e7%a2%bc-201-created%ef%bc%88%e5%b7%b2%e5%89%b5%e5%bb%ba%ef%bc%89","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/47108\/","title":{"rendered":"IIS\u72c0\u614b\u78bc &#8211; 201 Created\uff08\u5df2\u5275\u5efa\uff09"},"content":{"rendered":"<h1 id=\"iis%e7%8b%80%e6%85%8b%e7%a2%bc-201-created%ef%bc%88%e5%b7%b2%e5%89%b5%e5%bb%ba%ef%bc%89-vyrUUHXQBt\">IIS\u72c0\u614b\u78bc &#8211; 201 Created\uff08\u5df2\u5275\u5efa\uff09<\/h1>\n<p>\u5728\u7db2\u7d61\u61c9\u7528\u7a0b\u5e8f\u7684\u958b\u767c\u548c\u7ba1\u7406\u4e2d\uff0cHTTP\u72c0\u614b\u78bc\u626e\u6f14\u8457\u81f3\u95dc\u91cd\u8981\u7684\u89d2\u8272\u3002\u9019\u4e9b\u72c0\u614b\u78bc\u4e0d\u50c5\u80fd\u5920\u5e6b\u52a9\u958b\u767c\u8005\u4e86\u89e3\u8acb\u6c42\u7684\u7d50\u679c\uff0c\u9084\u80fd\u6307\u5c0e\u7528\u6236\u5982\u4f55\u9032\u4e00\u6b65\u64cd\u4f5c\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0eIIS\uff08Internet Information Services\uff09\u4e2d\u7684\u72c0\u614b\u78bc201 Created\uff08\u5df2\u5275\u5efa\uff09\uff0c\u4e26\u5206\u6790\u5176\u5728\u5be6\u969b\u61c9\u7528\u4e2d\u7684\u610f\u7fa9\u548c\u4f7f\u7528\u5834\u666f\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af201-created%e7%8b%80%e6%85%8b%e7%a2%bc%ef%bc%9f-vyrUUHXQBt\">\u4ec0\u9ebc\u662f201 Created\u72c0\u614b\u78bc\uff1f<\/h2>\n<p>HTTP\u72c0\u614b\u78bc201 Created\u8868\u793a\u8acb\u6c42\u5df2\u6210\u529f\u8655\u7406\uff0c\u4e26\u4e14\u5df2\u7d93\u5275\u5efa\u4e86\u4e00\u500b\u65b0\u7684\u8cc7\u6e90\u3002\u9019\u500b\u72c0\u614b\u78bc\u901a\u5e38\u5728\u4f7f\u7528HTTP POST\u8acb\u6c42\u6642\u8fd4\u56de\uff0c\u7279\u5225\u662f\u5728\u5275\u5efa\u65b0\u8cc7\u6e90\u7684\u60c5\u6cc1\u4e0b\u3002\u7576\u4f3a\u670d\u5668\u6210\u529f\u8655\u7406\u8acb\u6c42\u4e26\u5275\u5efa\u8cc7\u6e90\u5f8c\uff0c\u6703\u8fd4\u56de\u6b64\u72c0\u614b\u78bc\uff0c\u4e26\u4e14\u901a\u5e38\u6703\u5728\u97ff\u61c9\u4e2d\u5305\u542b\u65b0\u5275\u5efa\u8cc7\u6e90\u7684URI\u3002<\/p>\n<h2 id=\"201-created%e7%9a%84%e4%bd%bf%e7%94%a8%e5%a0%b4%e6%99%af-vyrUUHXQBt\">201 Created\u7684\u4f7f\u7528\u5834\u666f<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u4f7f\u7528\u5834\u666f\uff0c\u8aaa\u660e\u4f55\u6642\u6703\u8fd4\u56de201 Created\u72c0\u614b\u78bc\uff1a<\/p>\n<ul>\n<li><strong>\u5275\u5efa\u65b0\u7528\u6236\uff1a<\/strong>\u7576\u7528\u6236\u5728\u8a3b\u518a\u9801\u9762\u63d0\u4ea4\u4fe1\u606f\u6642\uff0c\u4f3a\u670d\u5668\u6210\u529f\u5275\u5efa\u65b0\u7528\u6236\u8cec\u865f\u5f8c\uff0c\u6703\u8fd4\u56de201\u72c0\u614b\u78bc\u3002<\/li>\n<li><strong>\u4e0a\u50b3\u6587\u4ef6\uff1a<\/strong>\u7576\u7528\u6236\u4e0a\u50b3\u6587\u4ef6\u81f3\u4f3a\u670d\u5668\uff0c\u4e26\u4e14\u4f3a\u670d\u5668\u6210\u529f\u4fdd\u5b58\u8a72\u6587\u4ef6\u6642\uff0c\u6703\u8fd4\u56de201\u72c0\u614b\u78bc\u3002<\/li>\n<li><strong>\u65b0\u589e\u6578\u64da\u689d\u76ee\uff1a<\/strong>\u5728RESTful API\u4e2d\uff0c\u7576\u5ba2\u6236\u7aef\u767c\u9001POST\u8acb\u6c42\u4ee5\u65b0\u589e\u6578\u64da\u689d\u76ee\u6642\uff0c\u4f3a\u670d\u5668\u6210\u529f\u8655\u7406\u8acb\u6c42\u4e26\u5275\u5efa\u65b0\u689d\u76ee\u5f8c\uff0c\u6703\u8fd4\u56de201\u72c0\u614b\u78bc\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%af%a6%e7%8f%be201-created%e7%8b%80%e6%85%8b%e7%a2%bc-vyrUUHXQBt\">\u5982\u4f55\u5be6\u73fe201 Created\u72c0\u614b\u78bc<\/h2>\n<p>\u5728IIS\u4e2d\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u901a\u904e\u7de8\u5beb\u76f8\u61c9\u7684\u4ee3\u78bc\u4f86\u8fd4\u56de201 Created\u72c0\u614b\u78bc\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u4f7f\u7528ASP.NET\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>\npublic IHttpActionResult CreateUser(UserModel userModel)\n{\n    if (userModel == null)\n    {\n        return BadRequest();\n    }\n\n    \/\/ \u5047\u8a2d\u9019\u88e1\u6709\u4ee3\u78bc\u5c07\u7528\u6236\u6578\u64da\u4fdd\u5b58\u5230\u6578\u64da\u5eab\n    var newUser = SaveUserToDatabase(userModel);\n\n    \/\/ \u8fd4\u56de201 Created\u72c0\u614b\u78bc\uff0c\u4e26\u5305\u542b\u65b0\u7528\u6236\u7684URI\n    var uri = Url.Link(\"GetUserById\", new { id = newUser.Id });\n    return Created(uri, newUser);\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u793a\u4f8b\u4e2d\uff0c\u7576\u7528\u6236\u6210\u529f\u5275\u5efa\u5f8c\uff0c\u4f3a\u670d\u5668\u6703\u8fd4\u56de201\u72c0\u614b\u78bc\uff0c\u4e26\u5728\u97ff\u61c9\u4e2d\u5305\u542b\u65b0\u7528\u6236\u7684URI\uff0c\u9019\u6a23\u5ba2\u6236\u7aef\u5c31\u53ef\u4ee5\u65b9\u4fbf\u5730\u8a2a\u554f\u8a72\u8cc7\u6e90\u3002<\/p>\n<h2 id=\"201-created%e7%9a%84%e9%9f%bf%e6%87%89%e7%a4%ba%e4%be%8b-vyrUUHXQBt\">201 Created\u7684\u97ff\u61c9\u793a\u4f8b<\/h2>\n<p>\u4ee5\u4e0b\u662f\u4e00\u500b201 Created\u72c0\u614b\u78bc\u7684HTTP\u97ff\u61c9\u793a\u4f8b\uff1a<\/p>\n<pre><code>\nHTTP\/1.1 201 Created\nLocation: http:\/\/example.com\/users\/123\nContent-Type: application\/json\n\n{\n    \"id\": 123,\n    \"name\": \"John Doe\",\n    \"email\": \"john.doe@example.com\"\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u97ff\u61c9\u4e2d\uff0c\u4f3a\u670d\u5668\u8fd4\u56de\u4e86201\u72c0\u614b\u78bc\uff0c\u4e26\u5728Location\u6a19\u982d\u4e2d\u63d0\u4f9b\u4e86\u65b0\u5275\u5efa\u8cc7\u6e90\u7684URI\uff0c\u540c\u6642\u9084\u8fd4\u56de\u4e86\u65b0\u7528\u6236\u7684\u8a73\u7d30\u4fe1\u606f\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-vyrUUHXQBt\">\u7e3d\u7d50<\/h2>\n<p>HTTP\u72c0\u614b\u78bc201 Created\u5728\u7db2\u7d61\u61c9\u7528\u7a0b\u5e8f\u4e2d\u5177\u6709\u91cd\u8981\u7684\u610f\u7fa9\uff0c\u7279\u5225\u662f\u5728\u8cc7\u6e90\u5275\u5efa\u7684\u904e\u7a0b\u4e2d\u3002\u901a\u904e\u6b63\u78ba\u4f7f\u7528\u9019\u500b\u72c0\u614b\u78bc\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6e05\u6670\u5730\u5411\u5ba2\u6236\u7aef\u50b3\u9054\u8acb\u6c42\u7684\u7d50\u679c\uff0c\u4e26\u63d0\u4f9b\u5f8c\u7e8c\u64cd\u4f5c\u7684\u6307\u5f15\u3002\u5c0d\u65bc\u5e0c\u671b\u5728\u9999\u6e2f\u5c0b\u627e\u9ad8\u6548\u80fd\u7684\u89e3\u6c7a\u65b9\u6848\u7684\u958b\u767c\u8005\u548c\u4f01\u696d\uff0c\u4e86\u89e3\u9019\u4e9b\u72c0\u614b\u78bc\u7684\u4f7f\u7528\u5c07\u6709\u52a9\u65bc\u63d0\u5347\u61c9\u7528\u7a0b\u5e8f\u7684\u7528\u6236\u9ad4\u9a57\u3002\u5982\u679c\u60a8\u5c0d\u65bcVPS\u6216\u5176\u4ed6\u4f3a\u670d\u5668\u89e3\u6c7a\u65b9\u6848\u611f\u8208\u8da3\uff0c\u6b61\u8fce\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9 <a href=\"https:\/\/server.hk\">Server.HK<\/a> \u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3IIS\u72c0\u614b\u78bc201 Created\u7684\u542b\u7fa9\uff0c\u8a72\u78bc\u8868\u793a\u8acb\u6c42\u6210\u529f\u4e14\u5df2\u5275\u5efa\u65b0\u8cc7\u6e90\uff0c\u9069\u7528\u65bcPOST\u8acb\u6c42\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-47108","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/47108","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=47108"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/47108\/revisions"}],"predecessor-version":[{"id":47109,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/47108\/revisions\/47109"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=47108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=47108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=47108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}