I want to ask a question about the
multipart/form-data. In the HTTP header, I find that the
Content-Type: multipart/form-data; boundary=???.
??? free to be defined by the user? Or it is generally from the HTML? Is it possible for me to define the
??? = abcdefg?
Is the ??? free define by the user?
or it is general from the HTML?
No. HTML has nothing to do with that. Read below.
Is it possible for me to define the ??? = abcdefg?
If you want to send the following data to the web server:
name = John age = 12
application/x-www-form-urlencoded would be like this:
As you might see, the server knows that parameters are separated by
&, and if
& is required as a parameter value, it will be encoded.
Now, how does the server knows where a parameter value starts and ends when it receives an HTTP request using
multipart/form-data? Using the boundary, similar to
--XXX Content-Disposition: form-data; name="name" John --XXX Content-Disposition: form-data; name="age" 12 --XXX--
In that case, the boundary value is
XXX. You specify it in the
Content-Type header so that the server knows how to split the data sent.
So, you basically need to:
- Use a value that won't appear in the HTTP data sent to the server.
- Be consistent and use the same value all over the request.