简体   繁体   English

FOSRestBundle jsonp请求下载力

[英]FOSRestBundle jsonp request force to download

My config for fos_rest section: 我对fos_rest部分的配置:

fos_rest:
    serializer:
        serialize_null: true
    view:
        view_response_listener: force
        force_redirects:
            html: true
        formats:
            jsonp: true
            json: true
            xml: false
            rss: false
        templating_formats:
            html: false
        mime_types:
            json: ['application/json', 'application/x-json', 'application/vnd.example-com.foo+json']
            jsonp: ['application/jsonp']
            rss: 'application/rss+xml'
            jpg: 'image/jpeg'
            png: 'image/png'
        jsonp_handler:
            callback_param:       callback
    body_listener: true
    param_fetcher_listener: force
    allowed_methods_listener: true
    access_denied_listener:
        json: true
    format_listener:
        rules:
          - { path: '^/', priorities: ['jsonp','json', 'xml'], fallback_format: json, prefer_extension: true }
    routing_loader:
        default_format: ~
    exception:
        codes:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
            'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT
        messages:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': true

When I try to access ie 当我尝试访问ie

http://10.0.0.10/users.jsonp?callback=call 

I have data forced to download and not displayed. 我有数据被迫下载而不显示。 Requested data is correct. 请求的数据是正确的。 How to make it display in the browser? 如何在浏览器中显示?

Change your config to: 将您的配置更改为:

fos_rest:
    ...
    view:
        ...
        jsonp_handler:
            callback_param: callback
            # add jsonp mime-type here
            # it's `application/javascript+jsonp` by default
            mime_type: application/javascript

If you're just wanting bug track the payload and you're on a *nix system, you can use curl for that sort of thing. 如果你只是想跟踪bug跟踪有效载荷并且你在* nix系统上,你可以使用curl这种事情。 Try something like this: 尝试这样的事情:

curl -i -X GET http://10.0.0.10/users.jsonp?callback=call

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM