{"id":6581,"date":"2024-09-20T19:16:35","date_gmt":"2024-09-20T11:16:35","guid":{"rendered":"https:\/\/t.n-years.com\/?p=6581"},"modified":"2024-09-20T19:16:35","modified_gmt":"2024-09-20T11:16:35","slug":"http-%e5%8d%8f%e8%ae%ae%e9%87%8c-multipart-form-data-%e7%9a%84%e5%ba%94%e7%94%a8%e5%9c%ba%e6%99%af%e8%af%b4%e6%98%8e","status":"publish","type":"post","link":"https:\/\/t.n-years.com\/?p=6581","title":{"rendered":"HTTP \u534f\u8bae\u91cc multipart\/form-data \u7684\u5e94\u7528\u573a\u666f\u8bf4\u660e"},"content":{"rendered":"<p>\u5173\u4e8e <code>multipart\/form-data<\/code> \u7684\u5e94\u7528\u573a\u666f\uff0cHTTP \u534f\u8bae\u5728 <a href=\"https:\/\/datatracker.ietf.org\/doc\/html\/rfc2388\">RFC 2388<\/a> \u4e2d\u5bf9\u5176\u8fdb\u884c\u4e86\u5b9a\u4e49\u548c\u89e3\u91ca\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u5f15\u7528\u6bb5\u843d\uff0c\u4ee5\u53ca\u5b83\u5728 HTTP \u8bf7\u6c42\u4e2d\u7684\u5e94\u7528\u573a\u666f\u7684\u89e3\u8bfb\uff1a<\/p>\n<h3>RFC 2388 \u5b9a\u4e49\u548c\u5e94\u7528\u573a\u666f\u89e3\u91ca\uff1a<\/h3>\n<pre><code>The media-type multipart\/form-data follows the rules of all multipart MIME data streams as outlined in RFC 2046. In forms, there are a series of fields to be supplied by the user who fills out the form. Each field has a name. For form data that involves files, each field has a type, and the entire stream of fields is a message body which is &quot;multipart&quot; because it represents a set of data items.<\/code><\/pre>\n<h3><strong>\u89e3\u91ca<\/strong><\/h3>\n<p><code>multipart\/form-data<\/code> \u662f\u4e00\u79cd MIME \u7c7b\u578b\uff0c\u8bbe\u8ba1\u7528\u4e8e\u5728 HTTP \u8bf7\u6c42\u4e2d\u5904\u7406\u591a\u90e8\u5206\u8868\u5355\u6570\u636e\u3002\u8be5\u683c\u5f0f\u7684\u6bcf\u4e2a\u5b57\u6bb5\u90fd\u53ef\u4ee5\u8868\u793a\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\uff0c\u5305\u62ec\u6587\u672c\u5b57\u6bb5\u548c\u6587\u4ef6\u5b57\u6bb5\u3002\u5b83\u7684\u4e3b\u8981\u7528\u9014\u662f\u5728\u9700\u8981\u4e0a\u4f20\u6587\u4ef6\u6216\u63d0\u4ea4\u590d\u6742\u8868\u5355\u65f6\u4f7f\u7528\uff0c\u4f46\u5b83\u4e5f\u53ef\u4ee5\u5904\u7406\u666e\u901a\u7684\u6587\u672c\u6570\u636e\u3002\u4e0b\u9762\u8be6\u7ec6\u63cf\u8ff0\u5b83\u7684\u5e94\u7528\u573a\u666f\uff1a<\/p>\n<h3><strong>\u5e94\u7528\u573a\u666f<\/strong><\/h3>\n<ol>\n<li>\n<p><strong>\u6587\u4ef6\u4e0a\u4f20<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5f53\u9700\u8981\u4ece\u5ba2\u6237\u7aef\u5411\u670d\u52a1\u5668\u4f20\u8f93\u4e00\u4e2a\u6216\u591a\u4e2a\u6587\u4ef6\u65f6\uff0c<code>multipart\/form-data<\/code> \u662f\u9996\u9009\u7684\u7f16\u7801\u683c\u5f0f\u3002\u6bcf\u4e2a\u6587\u4ef6\u53ef\u4ee5\u4f5c\u4e3a\u4e00\u4e2a\u72ec\u7acb\u7684 &quot;part&quot;\uff0c\u5141\u8bb8\u670d\u52a1\u5668\u5728\u5355\u4e2a\u8bf7\u6c42\u4e2d\u63a5\u6536\u591a\u4e2a\u6587\u4ef6\u548c\u5176\u4ed6\u8868\u5355\u5b57\u6bb5\u3002<\/li>\n<li>\u6587\u4ef6\u4e0a\u4f20\u573a\u666f\u901a\u5e38\u6d89\u53ca\u8868\u5355\u4e2d\u5305\u542b <code>input type=&quot;file&quot;<\/code> \u7684\u5b57\u6bb5\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u8868\u5355\u4e2d\u6709\u590d\u6742\u6570\u636e\u7ed3\u6784<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5f53\u8868\u5355\u4e2d\u5305\u542b\u6570\u7ec4\u3001\u5d4c\u5957\u5b57\u6bb5\u6216\u590d\u6742\u6570\u636e\u7ed3\u6784\u65f6\uff0c\u4f7f\u7528 <code>application\/x-www-form-urlencoded<\/code> \u53ef\u80fd\u4f1a\u53d8\u5f97\u590d\u6742\u3002<code>multipart\/form-data<\/code> \u80fd\u591f\u66f4\u7075\u6d3b\u5730\u5904\u7406\u8fd9\u4e9b\u7ed3\u6784\u5316\u6570\u636e\u3002<\/li>\n<li>\u6bd4\u5982\u5728\u8868\u5355\u4e2d\u4f20\u9012\u6570\u7ec4\u6216\u952e\u503c\u5bf9\u65f6\uff0c<code>multipart\/form-data<\/code> \u662f\u8f83\u4e3a\u5e38\u89c1\u7684\u9009\u62e9\uff0c\u56e0\u4e3a\u5b83\u5141\u8bb8\u4ee5\u8f83\u4e3a\u76f4\u89c2\u7684\u65b9\u5f0f\u6784\u9020\u8fd9\u4e9b\u6570\u636e\u3002<\/li>\n<\/ul>\n<\/li>\n<li>\n<p><strong>\u540c\u65f6\u4f20\u8f93\u6587\u672c\u548c\u4e8c\u8fdb\u5236\u6570\u636e<\/strong>\uff1a<\/p>\n<ul>\n<li>\u5982\u679c\u4e00\u4e2a\u8bf7\u6c42\u9700\u8981\u540c\u65f6\u4f20\u8f93\u6587\u672c\u6570\u636e\uff08\u5982\u8868\u5355\u5b57\u6bb5\uff09\u548c\u4e8c\u8fdb\u5236\u6570\u636e\uff08\u5982\u6587\u4ef6\uff09\uff0c<code>multipart\/form-data<\/code> \u662f\u7406\u60f3\u7684\u9009\u62e9\u3002\u8fd9\u79cd\u683c\u5f0f\u80fd\u591f\u8ba9\u8bf7\u6c42\u4f53\u5305\u542b\u591a\u4e2a\u90e8\u5206\uff0c\u6bcf\u4e2a\u90e8\u5206\u53ef\u4ee5\u662f\u4e0d\u540c\u7c7b\u578b\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<h3><strong>HTTP \u62a5\u6587\u793a\u4f8b<\/strong><\/h3>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e2a\u4f7f\u7528 <code>multipart\/form-data<\/code> \u7684 HTTP \u62a5\u6587\u793a\u4f8b\uff0c\u8868\u660e\u5b83\u5982\u4f55\u5904\u7406\u6df7\u5408\u7684\u8868\u5355\u5b57\u6bb5\u548c\u6587\u4ef6\uff1a<\/p>\n<pre><code class=\"language-http\">POST \/upload HTTP\/1.1\nHost: example.com\nContent-Type: multipart\/form-data; boundary=----WebKitFormBoundaryePkpFF7tjBAqx29L\nContent-Length: 233\n\n------WebKitFormBoundaryePkpFF7tjBAqx29L\nContent-Disposition: form-data; name=&quot;username&quot;\n\nJohnDoe\n------WebKitFormBoundaryePkpFF7tjBAqx29L\nContent-Disposition: form-data; name=&quot;file&quot;; filename=&quot;example.jpg&quot;\nContent-Type: image\/jpeg\n\n(binary data)\n------WebKitFormBoundaryePkpFF7tjBAqx29L--<\/code><\/pre>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d\uff0c<code>multipart\/form-data<\/code> \u88ab\u7528\u6765\u4e0a\u4f20\u7528\u6237\u540d\u548c\u4e00\u4e2a\u56fe\u7247\u6587\u4ef6\u3002\u6bcf\u4e2a\u5b57\u6bb5\u90fd\u5728 <code>boundary<\/code> \u5206\u9694\u7b26\u7684\u5e2e\u52a9\u4e0b\u88ab\u72ec\u7acb\u5904\u7406\uff0c\u786e\u4fdd\u6587\u672c\u548c\u4e8c\u8fdb\u5236\u6570\u636e\u90fd\u80fd\u4f20\u9012\u5230\u670d\u52a1\u5668\u3002<\/p>\n<h3><strong>\u603b\u7ed3<\/strong><\/h3>\n<ul>\n<li><strong>\u6587\u4ef6\u4e0a\u4f20<\/strong>\uff1a<code>multipart\/form-data<\/code> \u662f\u5904\u7406\u6587\u4ef6\u4e0a\u4f20\u7684\u9996\u9009\u683c\u5f0f\u3002<\/li>\n<li><strong>\u590d\u6742\u8868\u5355\u6570\u636e<\/strong>\uff1a\u80fd\u591f\u5904\u7406\u590d\u6742\u7684\u5d4c\u5957\u7ed3\u6784\u548c\u591a\u5b57\u6bb5\u7c7b\u578b\u3002<\/li>\n<li><strong>\u6df7\u5408\u6570\u636e<\/strong>\uff1a\u5141\u8bb8\u540c\u65f6\u4f20\u9012\u6587\u672c\u548c\u4e8c\u8fdb\u5236\u6570\u636e\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u5173\u4e8e multipart\/form-data \u7684\u5e94\u7528\u573a\u666f\uff0cHTTP \u534f\u8bae\u5728 RFC 2388 \u4e2d\u5bf9\u5176\u8fdb\u884c\u4e86\u5b9a\u4e49&#8230; <\/p>\n<div class=\"read-more navbutton\"><a href=\"https:\/\/t.n-years.com\/?p=6581\">\u9605\u8bfb\u66f4\u591a<i class=\"fa fa-angle-double-right\"><\/i><\/a><\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[123],"tags":[],"class_list":["post-6581","post","type-post","status-publish","format-standard","hentry","category-123"],"_links":{"self":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6581","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6581"}],"version-history":[{"count":1,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6581\/revisions"}],"predecessor-version":[{"id":6582,"href":"https:\/\/t.n-years.com\/index.php?rest_route=\/wp\/v2\/posts\/6581\/revisions\/6582"}],"wp:attachment":[{"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6581"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6581"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/t.n-years.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6581"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}