How can I prevent user-agents from presenting a download window for unrecognized mime types?

醉酒当歌 提交于 2019-12-11 02:48:34

问题


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 like 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?


回答1:


Another method I've used to debug JSON in the browser is the JSONView plugin for Firefox.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/1653445/how-can-i-prevent-user-agents-from-presenting-a-download-window-for-unrecognized

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!