How can I prevent user-agents from presenting a download window for unrecognized mime types?
If you set the Content-Disposition
header to attachment
, this causes user-agents to always present a download window for that file. I would like to do this opposite of this: force user-agents to always display the response directly. In this particular case, I have an API that's sending JSON. I'd l开发者_如何学Pythonike to serve it as application/json
as indicated by the specification, but since user-agents typically don't recognize the mime type, they present a download window. This makes debugging a real pain in the neck, so I'd like to work around this if I can. Suggestions?
Another method I've used to debug JSON in the browser is the JSONView plugin for Firefox.
As an alternative solution, you could add a query string or extension to the URL that, when present, sends it as text/plain instead. That way, you could debug by looking at http://example.com/path/to/json.txt, while real world usage still gets application/json.
From what I've been able to tell, there's not a universally reliable way to always make the content display inline.
I actually took two approaches to this. One, I wrote my own mini-browser so that I could see any response and issue PUT, POST and DELETE requests. The other is to run Fiddler, whilst making the request with the browser. You can see all the details in the request and response with Fiddler.
精彩评论