Boundary value of the header Content-Type is not applied to Request Payload and causing trouble

According to some well known sources the boundary value of the header Content-Type can be changed, MDN shows that too. But in my case it doesn’t happen, I don’t get it why.

When I inspect the console (Chrome, Firefox), the header is set correctly, as I defined it:
content-type: multipart/form-data; boundary=aBoundaryString

At the same time when I look at the request (in the console) I see data separated by ------WebKitFormBoundarymdIB1kNGNJ3dldnm in Chrome, and some big number-boundary in Firefox.


I use PHP on server side, and in this case when I try to read request data there via var_dump(file_get_contents('php://input')) I get result as string(0) "".

I have to say, that when I set the Content-Type header without “boundary”, like this:
content-type: multipart/form-data (and this is what I see in the console too)…

… in this case the Request Payload is also separated with the same browser boundaries, but in this case, on the server side, request data is not empty, but as it should be and separated with same boundaries which I see in browser console.


So what’s the problem, why can’t I change the boundary? I mean it’s definitely set, because I see that in the header Content-Type, but why isn’t it applied to the request?


Screenshots from the Firefox v100 console

first 3 images is a request without a boundary value

enter image description here

enter image description here

enter image description here

next 3 images is a request with a boundary value

enter image description here

enter image description here

enter image description here


there’s no difference if the file (uploads) is attached or not, result the same; and as I said in Chrome result the same

request sent via XMLHttpRequest, headers set by setRequestHeader()


If I understand correctly, when I explicitly specify the boundary, in my case, the problem is that the data is empty on the server because the receiver does not read it, because he sees a mismatch between the boundary in the header (which I set) and the boundary in the request (which set by browser itself)


according to the php.net/manual/en/wrappers.php.php: "php://input is not available with enctype="multipart/form-data", still when the header is set to the content-type: multipart/form-data without “boundary”, I have a correct data value in php://input. And in both cases i.e. with custom “boundary” and without it, the $_POST is an empty Array!

Well, the solution of my trouble is not to touch the Content-Type header at all, browser itself will generate it with a boundary and on the server side the data is available via $_POST and $_FILES. Still I don’t understand, can I set some custom boundary value of the header Content-Type or not, because in my case it didn’t work.