{"id":52926,"date":"2024-12-03T10:29:25","date_gmt":"2024-12-03T02:29:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/52926\/"},"modified":"2024-12-03T10:29:25","modified_gmt":"2024-12-03T02:29:25","slug":"%e5%8f%91%e9%80%81%e8%a1%a8%e5%8d%95%e6%95%b0%e6%8d%ae%e6%97%b6%ef%bc%8cboundary%e7%9a%84%e4%bd%9c%e7%94%a8%e6%98%af%e4%bb%80%e4%b9%88%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/52926\/","title":{"rendered":"\u53d1\u9001\u8868\u5355\u6570\u636e\u65f6\uff0cboundary\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>\u53d1\u9001\u8868\u5355\u6570\u636e\u65f6\uff0cboundary\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f<\/h1>\n<p>\u5077\u5077\u52aa\u529b\uff0c\u6084\u65e0\u58f0\u606f\u5730\u53d8\u5f3a\uff0c\u7136\u540e\u60ca\u8273\u6240\u6709\u4eba\uff01\u54c8\u54c8\uff0c\u5c0f\u4f19\u4f34\u4eec\u53c8\u6765\u5b66\u4e60\u5566~\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u53d1\u9001\u8868\u5355\u6570\u636e\u65f6\uff0cboundary\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f\u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u5bf9\u5176\u90fd\u6709\u591a\u5c11\u4e86\u89e3\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u770b\u4e00\u5427\uff01\u5f53\u7136\uff0c\u975e\u5e38\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u8bc4\u8bba\uff0c\u7ed9\u51fa\u5408\u7406\u7684\u5efa\u8bae\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\uff0c\u4e00\u8d77\u8fdb\u6b65\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241124\/17324496536743157558c67.jpg\" class=\"aligncenter\" title=\"\u53d1\u9001\u8868\u5355\u6570\u636e\u65f6\uff0cboundary\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" alt=\"\u53d1\u9001\u8868\u5355\u6570\u636e\u65f6\uff0cboundary\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>boundary\u5728\u53d1\u9001form-data\u6570\u636e\u65f6\u7684\u4f5c\u7528<\/strong><\/p>\n<p>\u5f53\u9700\u8981\u53d1\u9001\u8868\u5355\u6570\u636e\uff0c\u5305\u62ec\u6587\u4ef6\u5185\u5bb9\u65f6\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528multipart\/form-data\u7684\u5f62\u5f0f\u3002\u8fd9\u65f6\uff0c\u4f1a\u5728\u6570\u636e\u4e2d\u63d2\u5165\u4e00\u4e2a\u5206\u9694\u7b26boundary\uff0c\u7528\u4e8e\u5206\u9694\u4e0d\u540c\u7684\u8868\u5355\u5b57\u6bb5\u3002<\/p>\n<p><strong>\u81ea\u52a8\u8bbe\u7f6eboundary<\/strong><\/p>\n<p>\u5927\u591a\u6570\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u751f\u6210boundary\u503c\u3002\u5728\u53d1\u9001form-data\u6570\u636e\u65f6\uff0c\u4e0d\u9700\u8981\u624b\u52a8\u8bbe\u7f6eboundary\u3002<\/p>\n<p><strong>\u624b\u52a8\u8bbe\u7f6eboundary<\/strong><\/p>\n<p>\u867d\u7136\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u8bbe\u7f6eboundary\uff0c\u4f46\u4e5f\u53ef\u4ee5\u624b\u52a8\u8bbe\u7f6e\uff0c\u53ea\u9700\u5728ajax\u8bf7\u6c42\u4e2d\u6307\u5b9acontenttype\u4e2d\u7684boundary\u503c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>$.ajax({\n    ... \/\/ \u5176\u4ed6\u8bbe\u7f6e\n    contenttype: \"multipart\/form-data;boundary=\u81ea\u5b9a\u4e49\u7684boundary\u503c\",\n});<\/pre>\n<p><strong>\u83b7\u53d6boundary\u503c<\/strong><\/p>\n<p>\u83b7\u53d6boundary\u503c\u901a\u5e38\u6ca1\u6709\u5fc5\u8981\uff0c\u56e0\u4e3a\u5b83\u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u751f\u6210\u6216\u624b\u52a8\u8bbe\u7f6e\u7684\u3002\u5982\u679c\u51fa\u4e8e\u67d0\u79cd\u539f\u56e0\u9700\u8981\u83b7\u53d6boundary\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5e95\u5c42api\uff0c\u4f8b\u5982xmlhttprequest\u5bf9\u8c61\u7684getresponseheader()\u65b9\u6cd5\uff1a<\/p>\n<pre>var xhr = new XMLHttpRequest();\n\/\/ \u53d1\u9001form-data\u6570\u636e\nxhr.send(formData);\n\/\/ \u83b7\u53d6boundary\u503c\nvar boundary = xhr.getResponseHeader(\"Content-Type\").split(\"boundary=\")[1];<\/pre>\n<p><strong>\u5efa\u8bae<\/strong><\/p>\n<p>\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u5efa\u8bae\u4f7f\u7528\u6d4f\u89c8\u5668\u7684\u81ea\u52a8boundary\u8bbe\u7f6e\u3002\u624b\u52a8\u8bbe\u7f6eboundary\u53ef\u80fd\u4f1a\u5bfc\u81f4\u517c\u5bb9\u6027\u95ee\u9898\u6216\u5176\u4ed6\u610f\u5916\u884c\u4e3a\u3002\u5982\u679c\u51fa\u73b0\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u5c06contenttype\u8bbe\u7f6e\u4e3afalse\uff0c\u8ba9\u6d4f\u89c8\u5668\u81ea\u52a8\u5904\u7406boundary\u8bbe\u7f6e\u3002<\/p>\n<p>\u672c\u7bc7\u5173\u4e8e\u300a\u53d1\u9001\u8868\u5355\u6570\u636e\u65f6\uff0cboundary\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u82f9\u679c\u7535\u8111\u56fe\u7247\u4e0d\u80fd\u8ddf\u7740\u7a97\u53e3\u62d6\u62fd\u653e\u5927\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>\u53d1\u9001\u8868\u5355\u6570\u636e\u65f6\uff0cboundary\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f \u5077\u5077\u52aa\u529b\uff0c\u6084\u65e0\u58f0\u606f\u5730\u53d8\u5f3a\uff0c\u7136\u540e\u60ca\u8273\u6240\u6709\u4eba\uff01\u54c8\u54c8\uff0c\u5c0f\u4f19\u4f34\u4eec\u53c8\u6765\u5b66\u4e60\u5566~\u4eca\u5929\u6211\u5c06\u7ed9\u5927\u5bb6\u4ecb\u7ecd\u300a\u53d1\u9001\u8868\u5355\u6570\u636e\u65f6\uff0cboundary\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f\u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u4f1a\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\u70b9\uff0c\u4e0d\u77e5\u9053\u5927\u5bb6\u5bf9\u5176\u90fd\u6709\u591a\u5c11\u4e86\u89e3\uff0c\u4e0b\u9762\u6211\u4eec\u5c31\u4e00\u8d77\u6765\u770b\u4e00\u5427\uff01\u5f53\u7136\uff0c\u975e\u5e38\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u8bc4\u8bba\uff0c\u7ed9\u51fa\u5408\u7406\u7684\u5efa\u8bae\uff0c\u6211\u4eec\u4e00\u8d77\u5b66\u4e60\uff0c\u4e00\u8d77\u8fdb\u6b65\uff01 boundary\u5728\u53d1\u9001form-data\u6570\u636e\u65f6\u7684\u4f5c\u7528 \u5f53\u9700\u8981\u53d1\u9001\u8868\u5355\u6570\u636e\uff0c\u5305\u62ec\u6587\u4ef6\u5185\u5bb9\u65f6\uff0c\u901a\u5e38\u4f1a\u4f7f\u7528multipart\/form-data\u7684\u5f62\u5f0f\u3002\u8fd9\u65f6\uff0c\u4f1a\u5728\u6570\u636e\u4e2d\u63d2\u5165\u4e00\u4e2a\u5206\u9694\u7b26boundary\uff0c\u7528\u4e8e\u5206\u9694\u4e0d\u540c\u7684\u8868\u5355\u5b57\u6bb5\u3002 \u81ea\u52a8\u8bbe\u7f6eboundary \u5927\u591a\u6570\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u751f\u6210boundary\u503c\u3002\u5728\u53d1\u9001form-data\u6570\u636e\u65f6\uff0c\u4e0d\u9700\u8981\u624b\u52a8\u8bbe\u7f6eboundary\u3002 \u624b\u52a8\u8bbe\u7f6eboundary \u867d\u7136\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u8bbe\u7f6eboundary\uff0c\u4f46\u4e5f\u53ef\u4ee5\u624b\u52a8\u8bbe\u7f6e\uff0c\u53ea\u9700\u5728ajax\u8bf7\u6c42\u4e2d\u6307\u5b9acontenttype\u4e2d\u7684boundary\u503c\uff0c\u5982\u4e0b\u6240\u793a\uff1a $.ajax({ &#8230; \/\/ \u5176\u4ed6\u8bbe\u7f6e contenttype: &#8220;multipart\/form-data;boundary=\u81ea\u5b9a\u4e49\u7684boundary\u503c&#8221;, }); \u83b7\u53d6boundary\u503c \u83b7\u53d6boundary\u503c\u901a\u5e38\u6ca1\u6709\u5fc5\u8981\uff0c\u56e0\u4e3a\u5b83\u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u751f\u6210\u6216\u624b\u52a8\u8bbe\u7f6e\u7684\u3002\u5982\u679c\u51fa\u4e8e\u67d0\u79cd\u539f\u56e0\u9700\u8981\u83b7\u53d6boundary\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e9b\u5e95\u5c42api\uff0c\u4f8b\u5982xmlhttprequest\u5bf9\u8c61\u7684getresponseheader()\u65b9\u6cd5\uff1a var xhr = new XMLHttpRequest(); \/\/ \u53d1\u9001form-data\u6570\u636e xhr.send(formData); \/\/ \u83b7\u53d6boundary\u503c var boundary = xhr.getResponseHeader(&#8220;Content-Type&#8221;).split(&#8220;boundary=&#8221;)[1]; \u5efa\u8bae \u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u5efa\u8bae\u4f7f\u7528\u6d4f\u89c8\u5668\u7684\u81ea\u52a8boundary\u8bbe\u7f6e\u3002\u624b\u52a8\u8bbe\u7f6eboundary\u53ef\u80fd\u4f1a\u5bfc\u81f4\u517c\u5bb9\u6027\u95ee\u9898\u6216\u5176\u4ed6\u610f\u5916\u884c\u4e3a\u3002\u5982\u679c\u51fa\u73b0\u95ee\u9898\uff0c\u53ef\u4ee5\u5c1d\u8bd5\u5c06contenttype\u8bbe\u7f6e\u4e3afalse\uff0c\u8ba9\u6d4f\u89c8\u5668\u81ea\u52a8\u5904\u7406boundary\u8bbe\u7f6e\u3002 \u672c\u7bc7\u5173\u4e8e\u300a\u53d1\u9001\u8868\u5355\u6570\u636e\u65f6\uff0cboundary\u7684\u4f5c\u7528\u662f\u4ec0\u4e48\uff1f\u300b\u7684\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\u5566\uff0c\u4f46\u662f\u5b66\u65e0\u6b62\u5883\uff0c\u60f3\u8981\u4e86\u89e3\u5b66\u4e60\u66f4\u591a\u5173\u4e8e\u6587\u7ae0\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01 \u82f9\u679c\u7535\u8111\u56fe\u7247\u4e0d\u80fd\u8ddf\u7740\u7a97\u53e3\u62d6\u62fd\u653e\u5927\uff1f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-52926","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=52926"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/52926\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=52926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=52926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=52926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}