2

I am using fosrestbundle on Symfony3 to create a server side web-api.

fos_rest configuration of app/config/config.yml

fos_rest:
    param_fetcher_listener: true
    body_listener: true
    format_listener:
            enabled: true
            rules:
                - { path: ^/api, priorities: [ json ], fallback_format: json, prefer_extension: true }
    view:
        view_response_listener: 'force'
        formats:
            xml: true
            json : true
        templating_formats:
            html: true
        force_redirects:
            html: true
        failed_validation: HTTP_BAD_REQUEST
        default_engine: twig
    routing_loader:
        default_format: json

Whenever I am posting with Content-Type: x-www-form-urlencoded the Controller get hit. Each time I use application/json the response is 400 BAD REQUEST. But I need it to be Content-Type: application/json. Please tell me what should I change in fos_rest config so that it can accept application/json. Thanks in advance.

N.B. I tried Body Listener by the book. But no luck. Version change may be the problem. I don't know.

Sujit
  • 790
  • 1
  • 13
  • 27
  • 2
    It looks like the JSON that you send in the body of your request is not valid. How does your complete request look like? – xabbuh Dec 29 '15 at 09:40
  • yeah... its my mistake. I was trying with **Advanced Rest Client Application** Google Chrome Extension. I was sending post by form data but not json formatter. My BAD. Thanks anyway.@xabbuh – Sujit Dec 29 '15 at 09:51

1 Answers1

1

As @xabbuh mentioned, you are trying with wrong data format while requesting.

enter image description here

Instead of above, your request should look like this.

enter image description here

Atish Kumar Dipongkor
  • 10,220
  • 9
  • 49
  • 77