Upload files on the front end, Content-Type: multipart/form-data; boundary=----WebKitFormBoundarywd2ZRr4Hlgf2m5MT;

  • multipart/form-data is the content-type format for file transfer. In order to upload files, wait for the binary stream
  • boundary is the delimiter that separates multiple files and form items. If you do not set it yourself, it will be automatically generated by the browser by default and ensure to be unique in the entire request body so that the server can correctly parse each part of the request.
  • When submitting data using the multipart/form-data format, each request body part (part) needs to have a unique delimiter (boundary) to identify different parts. This delimiter is generated by the client and specified in the request header.
  • Typically, developers do not need to manually specify delimiters because most HTTP client libraries (such as the browser's built-in XMLHttpRequest, Fetch, or third-party libraries such as axios) automatically generate and handle these boundaries and delimiters for you.
  • The occurrence of ----WebKitFormBoundarywd2ZRr4Hlgf2m5MT in the example is just an example separator, not a fixed value. In practice, the generated delimiter may be random, and will be unique enough to ensure that it does not conflict with the actual data in the body.
  • So, the value in Content-Type: multipart/form-data; boundary=----WebKitFormBoundarywd2ZRr4Hlgf2m5MT is automatically generated and will have a different value in each specific requestboundary
  • Typically, an HTTP client library (such as the browser's built-in XMLHttpRequest, Fetch, or a third-party library such as axios) will automatically generate and add the correct delimiters and boundaries for you.
  • Regarding removing the space in front of boundary, it should be noted that according to the HTTP specification, the front of the delimiter can contain one or more space characters. Therefore, removing the space before boundary is not in compliance with the specification and may cause the request to not be parsed correctly.
  • It is recommended to keep the space before in the Content-Type request header to ensure consistency with the HTTP specification and avoid potential problems. boundary

Guess you like

Origin blog.csdn.net/choujima/article/details/132567207