I created a controller in a custom module that accepts a POST
request.
I have a setup such that I get a POST
request from a third-party application server to this API. But the POST
request has a Content-Type: "application/x-www-form-urlencoded"
in the header.
And because of this I get the following error in the recent log messages:
Symfony\Component\HttpKernel\Exception\UnsupportedMediaTypeHttpException: No route found that matches "Content-Type: application/x-www-form-urlencoded" in Drupal\Core\Routing\ContentTypeHeaderMatcher->filter() (line 49 of /var/www/html/web/core/lib/Drupal/Core/Routing/ContentTypeHeaderMatcher.php).```
When I test the API using postman:
- if I use the
Content-Type: "application/json"
in the header, the code inside the API is executed, and I get the correct response.
- if I use the
Content-Type: "application/x-www-form-urlencoded"
, I get the same error.
I cannot configure the third party application server to change the Content-Type
. So the only option for me is to configure the API to accept the POST
request with the Content-Type: "application/x-www-form-urlencoded"
. How can I do that?
Edited:
My class extends the class ResourceBase. Route definition of the controller. Also I am using drupal 8.
* @RestResource(
* id = "test_abc_callback",
* label = @Translation("Custom API for Test"),
* uri_paths = {
* "create" = "/api/v1/test_callback",
* }
* )