How do I set the correct json headers?

Deadly 提交于 2020-01-02 03:11:08

问题


Is there a way in htaccess to ensure the headers for my json are correct?

Update: Does anyone see anything wrong with these headers for json?

Date    Mon, 26 Jul 2010 08:31:11 GMT
Server  Apache/2.2.15 (Unix) mod_ssl/2.2.15 OpenSSL/0.9.7a mod_fcgid/2.3.5 Phusion_Passenger/2.2.15 mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635
X-Powered-By    PHP/5.2.13
X-Pingback  http://brettbarros.com/wordpress/xmlrpc.php
Content-Disposition attachment; filename="json_api.json"
Vary    Accept-Encoding
Content-Encoding    gzip
Content-Length  719
Keep-Alive  timeout=5, max=98
Connection  Keep-Alive
Content-Type    application/json; charset=UTF-8

Specifically, it's working with jquery's getJSON in ie8, ffx, chrome, but not ie7 or ie6...


回答1:


You can inspect the headers sent along from the server side using Firebug's Net tab. It shows all the headers for both the request and the response.




回答2:


AddType application/json .json

is a simple way to make all your *.json files being sent with the correct mime type. That, of course, doesn't work, if you create them dynamically in something like a, say, PHP script. In that case, you can add the info inside the script:

<?php
header('Content-Type: application/json');
// ...



回答3:


Make sure the Content-Type is application/json. You can inspect the http headers with wget and whatnot if you aren't sure what they are.



来源:https://stackoverflow.com/questions/3333196/how-do-i-set-the-correct-json-headers

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