资料还是得看英文原版的![转]How To Serve .json files from IIS7 when request is POST

http://stackoverflow.com/questions/7943270/how-to-serve-json-files-from-iis7-when-request-is-post

I have an asp.net 4.0 web site that needs to serve files of type .json. The request is coming in as a POST, which does not work. GET works fine. Anyone know what configuration I need to change to make this work?

share|improve this question
 
    
Just a note that it's a best practice to redirect to a GET after accepting a POST:en.wikipedia.org/wiki/Post/Redirect/Get –  Joel Coehoorn Oct 30 '11 at 4:40 
    
I'm mocking a server I can't control which means my javascript app needs to do the sam when going to my iis as it does to the production server which in this case is apache. So, to not change the javascript and simulate the same behavior in IIS, I need the javascript to do a POST to get the results (not GET) –  Peter KellnerOct 30 '11 at 21:59
    
I'm not happy doing this as a handler, but I needed it done. I posted my solution here:peterkellner.net/2011/10/30/… I'd still like to know a better answer. –  Peter Kellner Oct 31 '11 at 1:58

2 Answers

You probably already found the answer, but I think the problem lies in that you need to add a ".json" handler for your web server...

By default IIS is not configured to handle .json extension.

You can apply the mime type as a handler on the root of IIS so .json can be handled by every site or virtual folder in the IIS or just to the specific site.

  1. Open IIS Manager
  2. Display properties for the IIS Server
  3. Click MIME Types and then add the JSON extension:
    • File name extension: .json
    • MIME type: application/json(尝试过text/json、application/x-javascript都不行
  4. Go back to the properties for IIS Server
  5. Click on Handler Mappings(可省略)
    • Add a script map
    • Request path: *.json
    • Executable: C:\WINDOWS\system32\inetsrv\asp.dll
    • Name: JSON

(or Apache, if you're on the dev side...)

Apache Module mod_mime AddType

Note: In Ubuntu you ALSO need to edit the file /etc/mime.types and add the line:

application/json json

Then restart Apache

sudo /etc/init.d/apache2 restart
share|improve this answer
posted @ 2014-12-30 04:31  Johnsonton's blog  阅读(233)  评论(0)    收藏  举报