我使用fosrestbundle上Symfony3创建一个服务器端Web的API。
fos_rest配置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
每当我发布Content-Type:x-www-form-urlencoded的控制器时,都会被命中。每次我使用application / json时,响应都是400 BAD REQUEST。但是我需要它是Content-Type:application / json。请告诉我在fos_rest配置中应该更改什么,以便它可以接受application / json。提前致谢。
注意:我在本书中尝试过“身体听者”。但是没有运气。版本更改可能是问题所在。我不知道。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句