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=???
.
Is the ???
free to be defined by the user? Or is it generated from the HTML? Is it possible for me to define the ??? = abcdefg
?
Best Answer
Yes.
No. HTML has nothing to do with that. Read below.
Yes.
If you want to send the following data to the web server:
using
application/x-www-form-urlencoded
would be like this:As you can see, the server knows that parameters are separated by an ampersand
&
. If&
is required for a parameter value then it must be encoded.So how does the server know where a parameter value starts and ends when it receives an HTTP request using
multipart/form-data
?Using the boundary, similar to
&
.For example:
In that case, the boundary value is
XXX
. You specify it in theContent-Type
header so that the server knows how to split the data it receives.So you need to:
Use a value that won't appear in the HTTP data sent to the server.
Be consistent and use the same value everywhere in the request message.