0

I have a scenario in which a client application sends a POST request to an asp.net page to which the page responds with a json string which I need to consume on the client side. However, Internet explorer is trying to download the *.aspx page, containing the json string.

What HTTP headers must the response contain to disable the download in Internet Explorer?

Currently, the response HTTP headers are:

Access-Control-Allow-Headers:X-File-Name,X-File-Type,X-File-Size
Access-Control-Allow-Methods:GET,POST,OPTIONS
Access-Control-Allow-Origin:*
Cache-Control:private,private, no-cache
Content-Length:1050
Content-Type:application/json; charset=utf-8
Date:Fri, 12 Jul 2013 08:24:24 GMT
Pragma:no-cache
Server:Microsoft-IIS/7.5
Set-Cookie:ASP.NET_SessionId=qjudp3nct3czltyvc4yxpiri; path=/; HttpOnly
X-AspNet-Version:4.0.30319
X-Powered-By:ASP.NET
4

1 回答 1

0

这取决于您如何使用该 Web 服务。

如果您使用 jQuery 从网页内部使用它,这应该不是问题,Internet Explorer 不会强制下载该文件。

如果您在 POST 之后直接访问文件(重定向到提供 JSON 的 URL)并且希望将 JSON 显示为纯文本,则必须将 Content-Type 设置为 text/plain;字符集=utf-8

于 2013-07-13T14:39:06.850 回答