How can I prevent user-agents from presenting a do

2019-07-24 04:02发布

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?

3条回答
Summer. ? 凉城
2楼-- · 2019-07-24 04:18

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

查看更多
Lonely孤独者°
3楼-- · 2019-07-24 04:21

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.

查看更多
我欲成王,谁敢阻挡
4楼-- · 2019-07-24 04:33

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.

查看更多
登录 后发表回答