Good afternoon, there was an interesting problem.

It is given: there is YII2 and there is a rest api interface. We send a multipart / form-data method post to url and then miracles begin.

enter image description here

As soon as I remove the boundary, everything starts working. However, I want to force it

Content-Type: multipart / form-data; boundary = X_PAW_BOUNDARY

Moreover, even the standard output of php content falls off.

$rawPost = file_get_contents('php://input'); var_dump($rawPost); die(); 

Standard operation with \ YII :: $ app-> request-> getRawBody () is also empty ..

Tell me what am I doing wrong? Thank.

    1 answer 1

    So: suppose a situation that we need to send a large multipart request with different data in one request. Json, XML, files. How to act in this case - the simplest solution (which I went to) is to send the rest request as a multipart / form-data and parse the RAW date using PHP. And this solution works, up to a certain point ... The whole thing is that as soon as we add a custom boundary to the headers, the multiplicate falls. And it's not strange - there is no RAW date either through php input, or through $ _POST, $ _REQUEST. Having overclocked a lot of documentation, I realized that this error was not a YII framework and not even PHP. According to RFC 1341, section 7.2.1 for HTTP, such complex requests should be transmitted as Content-Type: multipart / mixed; boundary = gc0p4Jq0M2Yt08jU534c0p. notice MIXED, which means mixed