问题
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?
回答1:
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.
- Open IIS Manager
- Display properties for the IIS Server
- Click MIME Types and then add the JSON extension:
- File name extension: .json
- MIME type: application/json
- Go back to the properties for IIS Server
- 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
回答2:
GET or POST is irrelevant, its got nothing to do with the type of response your program sends. There is no setting that would make a difference. Your problem is a logic error in your program.
来源:https://stackoverflow.com/questions/7943270/how-to-serve-json-files-from-iis7-when-request-is-post