{"id":53372,"date":"2024-12-03T09:10:17","date_gmt":"2024-12-03T01:10:17","guid":{"rendered":"https:\/\/fwq.ai\/blog\/53372\/"},"modified":"2024-12-03T09:10:17","modified_gmt":"2024-12-03T01:10:17","slug":"form-data-%e6%95%b0%e6%8d%ae%e4%bc%a0%e8%be%93%e4%b8%ad%e7%9a%84-boundary-%e6%98%af%e7%94%b1%e6%b5%8f%e8%a7%88%e5%99%a8%e8%87%aa%e5%8a%a8%e8%ae%be%e7%bd%ae%e7%9a%84%e5%90%97%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/53372\/","title":{"rendered":"Form-data \u6570\u636e\u4f20\u8f93\u4e2d\u7684 boundary \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u8bbe\u7f6e\u7684\u5417\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>Form-data \u6570\u636e\u4f20\u8f93\u4e2d\u7684 boundary \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u8bbe\u7f6e\u7684\u5417\uff1f <\/h1>\n<p>\u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u7c73\u4e91\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300aForm-data \u6570\u636e\u4f20\u8f93\u4e2d\u7684 boundary \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u8bbe\u7f6e\u7684\u5417\uff1f \u300b<\/span>\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241129\/17328821756749aeff86b7a.jpg\" class=\"aligncenter\" title=\"Form-data \u6570\u636e\u4f20\u8f93\u4e2d\u7684 boundary \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u8bbe\u7f6e\u7684\u5417\uff1f\u63d2\u56fe\" alt=\"Form-data \u6570\u636e\u4f20\u8f93\u4e2d\u7684 boundary \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u8bbe\u7f6e\u7684\u5417\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>form-data \u6570\u636e\u4f20\u8f93\u4e2d\u7684 boundary<\/strong><\/p>\n<p>\u5728\u53d1\u9001 form-data \u7c7b\u578b\u6570\u636e\u65f6\uff0cboundary \u662f\u4e00\u79cd\u5206\u9694\u7b26\uff0c\u7528\u4e8e\u5c06\u4e0d\u540c\u7684\u6570\u636e\u5b57\u6bb5\u5206\u9694\u5f00\u3002\u90a3\u4e48\uff0cboundary \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u8bbe\u7f6e\u7684\u5417\uff1f<\/p>\n<p><strong>\u56de\u7b54\uff1a<\/strong><\/p>\n<p>\u662f\u7684\uff0c\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u751f\u6210 boundary\uff0c\u65e0\u9700\u624b\u52a8\u8bbe\u7f6e\u3002\u5b83\u4f5c\u4e3a Content-Type \u5934\u7684\u4e00\u90e8\u5206\u53d1\u9001\uff0c\u683c\u5f0f\u4e3a multipart\/form-data; boundary=xxx\uff0c\u5176\u4e2d xxx \u662f\u751f\u6210\u7684 boundary \u503c\u3002<\/p>\n<p><strong>\u624b\u52a8\u8bbe\u7f6e boundary<\/strong><\/p>\n<p>\u867d\u7136\u6d4f\u89c8\u5668\u53ef\u4ee5\u81ea\u52a8\u751f\u6210 boundary\uff0c\u4f46\u4f60\u4e5f\u53ef\u4ee5\u6839\u636e\u9700\u8981\u624b\u52a8\u8bbe\u7f6e\u5b83\u3002\u5728 jQuery \u7684 $.ajax() \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 contentType \u9009\u9879\u6307\u5b9a boundary \u503c\uff0c\u5982\u4e0b\u6240\u793a\uff1a<\/p>\n<pre>$.ajax({\n  type: \"post\",\n  url: \"\/login\",\n  data: formData,\n  success: function(res) {},\n  processData: false,\n  contentType: \"multipart\/form-data; boundary=my-custom-boundary\",\n  error: function(xhr) {\n    console.log(xhr);\n  }\n});<\/pre>\n<p><strong>\u83b7\u53d6 boundary \u503c<\/strong><\/p>\n<p>\u4e00\u822c\u60c5\u51b5\u4e0b\uff0c\u83b7\u53d6 boundary \u503c\u6ca1\u6709\u5fc5\u8981\uff0c\u56e0\u4e3a\u8fd9\u662f\u6d4f\u89c8\u5668\u6216\u670d\u52a1\u5668\u7aef\u5904\u7406\u7684\u4e8b\u60c5\u3002\u4f46\u662f\u5728\u7279\u6b8a\u60c5\u51b5\u4e0b\uff0c\u5982\u679c\u4f60\u9700\u8981\u83b7\u53d6\u5b83\uff0c\u53ef\u4ee5\u901a\u8fc7\u67e5\u770b Response Headers \u6765\u67e5\u627e Content-Type \u5934\u90e8\uff0c\u5176\u4e2d\u5305\u542b boundary \u4fe1\u606f\u3002<\/p>\n<p><strong>\u63d0\u793a<\/strong><\/p>\n<p>\u5982\u679c\u4f60\u624b\u52a8\u8bbe\u7f6e\u4e86 contentType \u5e76\u9047\u5230\u4e86\u9519\u8bef\uff0c\u53ef\u80fd\u662f\u540e\u7aef\u670d\u52a1\u5668\u65e0\u6cd5\u6b63\u786e\u89e3\u6790\u8bf7\u6c42\u3002\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u4f60\u53ef\u4ee5\u5c1d\u8bd5\u5c06 contentType \u8bbe\u7f6e\u4e3a false\uff0c\u8ba9\u6d4f\u89c8\u5668\u81ea\u52a8\u751f\u6210\u548c\u53d1\u9001 boundary\u3002<\/p>\n<p>\u4eca\u5929\u5173\u4e8e\u300aForm-data \u6570\u636e\u4f20\u8f93\u4e2d\u7684 boundary \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u8bbe\u7f6e\u7684\u5417\uff1f \u300b\u7684\u5185\u5bb9\u5c31\u4ecb\u7ecd\u5230\u8fd9\u91cc\u4e86\uff0c\u662f\u4e0d\u662f\u5b66\u8d77\u6765\u4e00\u76ee\u4e86\u7136\uff01\u60f3\u8981\u4e86\u89e3\u66f4\u591a\u5173\u4e8e\u7684\u5185\u5bb9\u8bf7\u5173\u6ce8\u7c73\u4e91\u516c\u4f17\u53f7\uff01<\/p>\n<dl>\n<dt><\/dt>\n<dd>\n   \u5728 iframe \u4e2d\u5c55\u793a\u77ed\u94fe\u63a5\u91cd\u5b9a\u5411\u540e\u7684\u5185\u5bb9\uff0c\u8be5\u600e\u4e48\u505a\uff1f\n <\/dd>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>Form-data \u6570\u636e\u4f20\u8f93\u4e2d\u7684 boundary \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u8bbe\u7f6e\u7684\u5417\uff1f \u6b22\u8fce\u5404\u4f4d\u5c0f\u4f19\u4f34\u6765\u5230\u7c73\u4e91\uff0c\u76f8\u805a\u4e8e\u6b64\u90fd\u662f\u7f18\u54c8\u54c8\u54c8\uff01\u4eca\u5929\u6211\u7ed9\u5927\u5bb6\u5e26\u6765\u300aForm-data \u6570\u636e\u4f20\u8f93\u4e2d\u7684 boundary \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u8bbe\u7f6e\u7684\u5417\uff1f \u300b\uff0c\u8fd9\u7bc7\u6587\u7ae0\u4e3b\u8981\u8bb2\u5230\u7b49\u7b49\u77e5\u8bc6\uff0c\u5982\u679c\u4f60\u5bf9\u6587\u7ae0\u76f8\u5173\u7684\u77e5\u8bc6\u975e\u5e38\u611f\u5174\u8da3\u6216\u8005\u6b63\u5728\u81ea\u5b66\uff0c\u90fd\u53ef\u4ee5\u5173\u6ce8\u6211\uff0c\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u6587\u7ae0\uff01\u5f53\u7136\uff0c\u6709\u4ec0\u4e48\u5efa\u8bae\u4e5f\u6b22\u8fce\u5728\u8bc4\u8bba\u7559\u8a00\u63d0\u51fa\uff01\u4e00\u8d77\u5b66\u4e60\uff01 form-data \u6570\u636e\u4f20\u8f93\u4e2d\u7684 boundary \u5728\u53d1\u9001 form-data \u7c7b\u578b\u6570\u636e\u65f6\uff0cboundary \u662f\u4e00\u79cd\u5206\u9694\u7b26\uff0c\u7528\u4e8e\u5c06\u4e0d\u540c\u7684\u6570\u636e\u5b57\u6bb5\u5206\u9694\u5f00\u3002\u90a3\u4e48\uff0cboundary \u662f\u7531\u6d4f\u89c8\u5668\u81ea\u52a8\u8bbe\u7f6e\u7684\u5417\uff1f \u56de\u7b54\uff1a \u662f\u7684\uff0c\u5728\u5927\u591a\u6570\u60c5\u51b5\u4e0b\uff0c\u6d4f\u89c8\u5668\u4f1a\u81ea\u52a8\u751f\u6210 boundary\uff0c\u65e0\u9700\u624b\u52a8\u8bbe\u7f6e\u3002\u5b83\u4f5c\u4e3a Content-Type \u5934\u7684\u4e00\u90e8\u5206\u53d1\u9001\uff0c\u683c\u5f0f\u4e3a multipart\/form-data; boundary=xxx\uff0c\u5176\u4e2d xxx \u662f\u751f\u6210\u7684 boundary \u503c\u3002 \u624b\u52a8\u8bbe\u7f6e boundary \u867d\u7136\u6d4f\u89c8\u5668\u53ef\u4ee5\u81ea\u52a8\u751f\u6210 boundary\uff0c\u4f46\u4f60\u4e5f\u53ef\u4ee5\u6839\u636e\u9700\u8981\u624b\u52a8\u8bbe\u7f6e\u5b83\u3002\u5728 jQuery \u7684 $.ajax() \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528 contentType \u9009\u9879\u6307\u5b9a boundary \u503c\uff0c\u5982\u4e0b\u6240\u793a\uff1a $.ajax({ type: &#8220;post&#8221;, url: &#8220;\/login&#8221;, data: formData, success: function(res) {}, processData: false, contentType: &#8220;multipart\/form-data; boundary=my-custom-boundary&#8221;, [&hellip;]<\/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-53372","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53372","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=53372"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/53372\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=53372"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=53372"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=53372"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}