{"id":47880,"date":"2024-10-07T17:19:15","date_gmt":"2024-10-07T09:19:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/47880\/"},"modified":"2024-10-07T17:19:15","modified_gmt":"2024-10-07T09:19:15","slug":"iis-%e5%ae%89%e5%85%a8%e6%95%99%e7%a8%8b%ef%bc%9a%e4%bd%bf%e7%94%a8-content-type-%e6%a8%99%e9%a0%ad%e6%ad%a3%e7%a2%ba%e8%99%95%e7%90%86%e5%85%a7%e5%ae%b9","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/47880\/","title":{"rendered":"IIS \u5b89\u5168\u6559\u7a0b\uff1a\u4f7f\u7528 Content-Type \u6a19\u982d\u6b63\u78ba\u8655\u7406\u5167\u5bb9"},"content":{"rendered":"<h1 id=\"iis-%e5%ae%89%e5%85%a8%e6%95%99%e7%a8%8b%ef%bc%9a%e4%bd%bf%e7%94%a8-content-type-%e6%a8%99%e9%a0%ad%e6%ad%a3%e7%a2%ba%e8%99%95%e7%90%86%e5%85%a7%e5%ae%b9-yzDcnxpPzK\">IIS \u5b89\u5168\u6559\u7a0b\uff1a\u4f7f\u7528 Content-Type \u6a19\u982d\u6b63\u78ba\u8655\u7406\u5167\u5bb9<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u5b89\u5168\u6027\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002\u5c0d\u65bc\u4f7f\u7528 Internet Information Services (IIS) \u7684\u7db2\u7ad9\u4f86\u8aaa\uff0c\u6b63\u78ba\u8655\u7406 HTTP \u6a19\u982d\uff0c\u7279\u5225\u662f Content-Type \u6a19\u982d\uff0c\u662f\u78ba\u4fdd\u7db2\u7ad9\u5b89\u5168\u7684\u95dc\u9375\u6b65\u9a5f\u4e4b\u4e00\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e\u5982\u4f55\u4f7f\u7528 Content-Type \u6a19\u982d\u4f86\u589e\u5f37 IIS \u7684\u5b89\u5168\u6027\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-content-type-%e6%a8%99%e9%a0%ad%ef%bc%9f-yzDcnxpPzK\">\u4ec0\u9ebc\u662f Content-Type \u6a19\u982d\uff1f<\/h2>\n<p>Content-Type \u6a19\u982d\u662f HTTP \u5354\u8b70\u4e2d\u7684\u4e00\u500b\u91cd\u8981\u90e8\u5206\uff0c\u7528\u65bc\u544a\u8a34\u5ba2\u6236\u7aef\uff08\u5982\u700f\u89bd\u5668\uff09\u6240\u63a5\u6536\u5167\u5bb9\u7684\u985e\u578b\u3002\u9019\u500b\u6a19\u982d\u53ef\u4ee5\u5e6b\u52a9\u700f\u89bd\u5668\u6b63\u78ba\u5730\u89e3\u6790\u548c\u986f\u793a\u5167\u5bb9\u3002\u4f8b\u5982\uff0c\u7576\u4f3a\u670d\u5668\u767c\u9001\u4e00\u500b HTML \u6587\u4ef6\u6642\uff0cContent-Type \u6a19\u982d\u6703\u8a2d\u7f6e\u70ba <code>text\/html<\/code>\uff1b\u800c\u5c0d\u65bc JSON \u6578\u64da\uff0c\u5247\u8a2d\u7f6e\u70ba <code>application\/json<\/code>\u3002<\/p>\n<h2 id=\"%e7%82%ba%e4%bb%80%e9%ba%bc-content-type-%e6%a8%99%e9%a0%ad%e5%b0%8d%e5%ae%89%e5%85%a8%e6%80%a7%e8%87%b3%e9%97%9c%e9%87%8d%e8%a6%81%ef%bc%9f-yzDcnxpPzK\">\u70ba\u4ec0\u9ebc Content-Type \u6a19\u982d\u5c0d\u5b89\u5168\u6027\u81f3\u95dc\u91cd\u8981\uff1f<\/h2>\n<p>\u4e0d\u6b63\u78ba\u7684 Content-Type \u6a19\u982d\u53ef\u80fd\u5c0e\u81f4\u591a\u7a2e\u5b89\u5168\u554f\u984c\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u8de8\u7ad9\u8173\u672c\u653b\u64ca (XSS)<\/strong>\uff1a\u5982\u679c\u4f3a\u670d\u5668\u932f\u8aa4\u5730\u5c07\u4e00\u500b JavaScript \u6587\u4ef6\u7684 Content-Type \u8a2d\u7f6e\u70ba <code>text\/plain<\/code>\uff0c\u700f\u89bd\u5668\u53ef\u80fd\u6703\u5c07\u5176\u8996\u70ba\u666e\u901a\u6587\u672c\uff0c\u5f9e\u800c\u7121\u6cd5\u57f7\u884c\u5176\u4e2d\u7684\u8173\u672c\uff0c\u9019\u53ef\u80fd\u6703\u5c0e\u81f4\u5b89\u5168\u6f0f\u6d1e\u3002<\/li>\n<li><strong>\u5167\u5bb9\u6df7\u6dc6<\/strong>\uff1a\u4e0d\u6b63\u78ba\u7684 Content-Type \u6a19\u982d\u53ef\u80fd\u6703\u5c0e\u81f4\u700f\u89bd\u5668\u932f\u8aa4\u5730\u89e3\u91cb\u5167\u5bb9\uff0c\u5f9e\u800c\u5f15\u767c\u5b89\u5168\u554f\u984c\u3002<\/li>\n<li><strong>\u6587\u4ef6\u4e0b\u8f09\u98a8\u96aa<\/strong>\uff1a\u5982\u679c\u4f3a\u670d\u5668\u672a\u6b63\u78ba\u8a2d\u7f6e Content-Type\uff0c\u53ef\u80fd\u6703\u5c0e\u81f4\u654f\u611f\u6587\u4ef6\u88ab\u932f\u8aa4\u5730\u4e0b\u8f09\u6216\u57f7\u884c\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e6%ad%a3%e7%a2%ba%e8%a8%ad%e7%bd%ae-content-type-%e6%a8%99%e9%a0%ad-yzDcnxpPzK\">\u5982\u4f55\u6b63\u78ba\u8a2d\u7f6e Content-Type \u6a19\u982d<\/h2>\n<p>\u5728 IIS \u4e2d\uff0c\u8a2d\u7f6e Content-Type \u6a19\u982d\u76f8\u5c0d\u7c21\u55ae\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6b65\u9a5f\u548c\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8-iis-%e7%ae%a1%e7%90%86%e5%99%a8%e8%a8%ad%e7%bd%ae-content-type-yzDcnxpPzK\">1. \u4f7f\u7528 IIS \u7ba1\u7406\u5668\u8a2d\u7f6e Content-Type<\/h3>\n<p>\u60a8\u53ef\u4ee5\u901a\u904e IIS \u7ba1\u7406\u5668\u4f86\u8a2d\u7f6e Content-Type \u6a19\u982d\uff1a<\/p>\n<ol>\n<li>\u6253\u958b IIS \u7ba1\u7406\u5668\u3002<\/li>\n<li>\u9078\u64c7\u60a8\u7684\u7db2\u7ad9\uff0c\u7136\u5f8c\u5728\u53f3\u5074\u7684\u529f\u80fd\u9762\u677f\u4e2d\u627e\u5230\u201c MIME \u985e\u578b\u201d\u3002<\/li>\n<li>\u5728 MIME \u985e\u578b\u4e2d\uff0c\u60a8\u53ef\u4ee5\u6dfb\u52a0\u3001\u7de8\u8f2f\u6216\u522a\u9664 Content-Type \u8a2d\u7f6e\u3002<\/li>\n<\/ol>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8-web-config-%e6%96%87%e4%bb%b6%e8%a8%ad%e7%bd%ae-content-type-yzDcnxpPzK\">2. \u4f7f\u7528 Web.config \u6587\u4ef6\u8a2d\u7f6e Content-Type<\/h3>\n<p>\u60a8\u4e5f\u53ef\u4ee5\u901a\u904e\u4fee\u6539\u7db2\u7ad9\u7684 <code>Web.config<\/code> \u6587\u4ef6\u4f86\u8a2d\u7f6e Content-Type\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u793a\u4f8b\uff1a<\/p>\n<pre><code>\n&lt;configuration&gt;\n    &lt;system.webServer&gt;\n        &lt;staticContent&gt;\n            &lt;mimeMap fileExtension=\".json\" mimeType=\"application\/json\" \/&gt;\n            &lt;mimeMap fileExtension=\".xml\" mimeType=\"application\/xml\" \/&gt;\n        &lt;\/staticContent&gt;\n    &lt;\/system.webServer&gt;\n&lt;\/configuration&gt;\n<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6%e5%92%8c%e9%a9%97%e8%ad%89-content-type-%e8%a8%ad%e7%bd%ae-yzDcnxpPzK\">\u6e2c\u8a66\u548c\u9a57\u8b49 Content-Type \u8a2d\u7f6e<\/h2>\n<p>\u8a2d\u7f6e\u5b8c Content-Type \u6a19\u982d\u5f8c\uff0c\u60a8\u61c9\u8a72\u9032\u884c\u6e2c\u8a66\u4ee5\u78ba\u4fdd\u5176\u6b63\u78ba\u6027\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u700f\u89bd\u5668\u7684\u958b\u767c\u8005\u5de5\u5177\u6216\u547d\u4ee4\u884c\u5de5\u5177\uff08\u5982 <code>curl<\/code>\uff09\u4f86\u6aa2\u67e5 HTTP \u97ff\u61c9\u6a19\u982d\u3002\u4f8b\u5982\uff1a<\/p>\n<pre><code>curl -I http:\/\/yourwebsite.com\/yourfile.json<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u97ff\u61c9\u6a19\u982d\uff0c\u60a8\u53ef\u4ee5\u6aa2\u67e5 <code>Content-Type<\/code> \u662f\u5426\u6b63\u78ba\u8a2d\u7f6e\u3002<\/p>\n<h2 id=\"%e7%b5%90%e8%ab%96-yzDcnxpPzK\">\u7d50\u8ad6<\/h2>\n<p>\u6b63\u78ba\u8a2d\u7f6e Content-Type \u6a19\u982d\u662f\u4fdd\u8b77 IIS \u7db2\u7ad9\u5b89\u5168\u7684\u91cd\u8981\u6b65\u9a5f\u3002\u901a\u904e\u9075\u5faa\u4e0a\u8ff0\u6b65\u9a5f\uff0c\u60a8\u53ef\u4ee5\u6709\u6548\u5730\u6e1b\u5c11\u6f5b\u5728\u7684\u5b89\u5168\u98a8\u96aa\uff0c\u4e26\u78ba\u4fdd\u7db2\u7ad9\u5167\u5bb9\u7684\u6b63\u78ba\u8655\u7406\u3002\u5c0d\u65bc\u5e0c\u671b\u9032\u4e00\u6b65\u63d0\u5347\u7db2\u7ad9\u5b89\u5168\u6027\u7684\u7528\u6236\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u670d\u52d9\uff0c\u4ee5\u7372\u5f97\u66f4\u9ad8\u7684\u63a7\u5236\u6b0a\u548c\u9748\u6d3b\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 IIS \u4e2d\u4f7f\u7528 Content-Type \u6a19\u982d\u6b63\u78ba\u8655\u7406\u5167\u5bb9\uff0c\u63d0\u5347\u7db2\u7ad9\u5b89\u5168\u6027\uff0c\u9632\u6b62\u6f5b\u5728\u7684\u653b\u64ca\u98a8\u96aa\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-47880","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/47880","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=47880"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/47880\/revisions"}],"predecessor-version":[{"id":47881,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/47880\/revisions\/47881"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=47880"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=47880"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=47880"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}