You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Description
I have had some issues trying to send (POST) data collections using the HttpClient component together with the Mime component.
The problem itself, or what I believe is a problem, lives on the Mime component.
Let's say I want to send a collection of names to the backend. Usually, what I've done can be seen on the code below:
As you can see, some names are repeated, and also, it is not actually well reconized by the server.
The result I got on this payload on Symfony ($request->request->all()) was:
There is a similar issue that can be found at #33063, which also has a PR (#33064).
I tested it, however, I didn't get what I believe is the desirable result.
…taPart (jvahldick)
This PR was merged into the 4.4 branch.
Discussion
----------
[Mime] Fixing multidimensional array structure with FormDataPart
| Q | A
| ------------- | ---
| Branch? | 4.3
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix#33063#34031
| License | MIT
| Doc PR | -
The issue is pretty much described on #34031
The current structure of the raw body build on FormDataPart is not well recognized by the server. It considers all the fields as a root type, when actually it is possible to send arrays by html forms.
Lets the following structure on the html
```html
<input type="text" name="names[]" value="John" />
<input type="text" name="names[]" value="Doe" />
```
It creates the following raw body:
```
----------------------------466490401959219490193856
Content-Disposition: form-data; name="names[]"
John
----------------------------466490401959219490193856
Content-Disposition: form-data; name="names[]"
Doe
----------------------------466490401959219490193856--
```
Meanwhile, the FormDataPart on Mime component generates the following body:
```
--_=_symfony_1571410799_b7846b3b4e86d821cdec4379e62b4068_=_
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Content-Disposition: form-data
John
--_=_symfony_1571410799_b7846b3b4e86d821cdec4379e62b4068_=_
Content-Type: text/plain; charset=utf-8; name=1
Content-Transfer-Encoding: 8bit
Content-Disposition: form-data; name=1
Doe
--_=_symfony_1571410799_b7846b3b4e86d821cdec4379e62b4068_=_--
```
For more complex structures, the $_POST doesn't even recognize properly the field names and values.
Commits
-------
ca630e5 Changing the multipart form-data behavior to use the form name as an array, which makes it recognizable as an array by PHP on the $_POST globals once it is coming from the HttpClient component
Symfony version(s) affected: 4.3
Description
I have had some issues trying to send (POST) data collections using the HttpClient component together with the Mime component.
The problem itself, or what I believe is a problem, lives on the Mime component.
Let's say I want to send a collection of names to the backend. Usually, what I've done can be seen on the code below:
It generates the following results on the $_POST globals on php
This is actual the raw body of the request:
So, I tried to do same using the Symfony HttpClient:
The raw body received on the server was:
Let's say I add more levels on the payload.
When building the form data, the fields are not well recognized as showing below
As you can see, some names are repeated, and also, it is not actually well reconized by the server.
The result I got on this payload on Symfony ($request->request->all()) was:
I created an example that can be checked at:
https://github.com/jvahldick/symfony-issue-mime-component/blob/master/src/Controller/MyController.php
There is a similar issue that can be found at #33063, which also has a PR (#33064).
I tested it, however, I didn't get what I believe is the desirable result.
What actually I expect to be the result is:
Possible Solution
Will be creating the PR.
The text was updated successfully, but these errors were encountered: