Skip to content

Content-Type HTTP application/x-www-form-urlencoded is return error

When i am using Content-Type: “application/x-www-form-urlencoded” in API i getting the error:

{
  "message": "Server cannot understand Content-Type HTTP header media type application/x-www-form-urlencoded",
  "trace": null
}

With Content-Type: “application/json” this works, but is necessary too with application/x-www-form-urlencoded.

I add deserializer in app/etc/di.xml

<type name="MagentoFrameworkWebapiRestRequestDeserializerFactory">
        <arguments>
            <argument name="deserializers" xsi:type="array">
                <item name="application_json" xsi:type="array">
                    <item name="type" xsi:type="string">application/json</item>
                    <item name="model" xsi:type="string">MagentoFrameworkWebapiRestRequestDeserializerJson</item>
                </item>
                <item name="application_xml" xsi:type="array">
                    <item name="type" xsi:type="string">application/xml</item>
                    <item name="model" xsi:type="string">MagentoFrameworkWebapiRestRequestDeserializerXml</item>
                </item>
                <item name="application_xhtml_xml" xsi:type="array">
                    <item name="type" xsi:type="string">application/xhtml+xml</item>
                    <item name="model" xsi:type="string">MagentoFrameworkWebapiRestRequestDeserializerXml</item>
                </item>
                <item name="text_xml" xsi:type="array">
                    <item name="type" xsi:type="string">text/xml</item>
                    <item name="model" xsi:type="string">MagentoFrameworkWebapiRestRequestDeserializerXml</item>
                </item>
                <item name="application_x_www_form_urlencoded" xsi:type="array">
                    <item name="type" xsi:type="string">application/x-www-form-urlencoded</item>
                    <item name="model" xsi:type="string">MagentoFrameworkWebapiRestRequestDeserializerJson</item>
                </item>
            </argument>
        </arguments>
    </type>

And get this response:

{
  "message": "The "string" value's type is invalid. The "string[]" type was expected. Verify and try again.",
  "trace": null
}

This is possible? And why Magento 2 not support application/x-www-form-urlencoded?

Thanks!