REST-Web服务响应-MIME类型? [英] REST - web service response - mime type?

查看:284
本文介绍了REST-Web服务响应-MIME类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1)为Web服务响应设置正确的mime类型是否重要?

1) Is it important to set the correct mime type for a web service response?

2)什么是a的正确mime类型,
a)XML响应?

2) what is the correct mime type for a,
a) XML response?

b)JSON响应?

application/xml 
text/xml
application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json

推荐答案

1)设置正确的重要吗 Web服务响应的MIME类型?

1) Is it important to set the correct mime type for a web service response?

绝对可以.如果您使用的是真正的REST API,则返回的不同媒体类型的文档是API规范的重要组成部分.

Absolutely yes. If you are doing a true REST API then documentation of the different Media Types you return is a vital part of your API specification.

2)正确的哑剧类型是什么 a,a)XML响应? b)JSON响应?

2) what is the correct mime type for a, a) XML response? b) JSON response?

对于真正的REST服务,这取决于您API的详细信息以及您定义为内容类型的内容.

For a true REST service, it depends on the details of your API and what you've defined as your content-types.

例如(摘自这篇出色的文章,值得一读完整),则银行可能希望为application/vnd.bank.org.account+xml的银行帐户定义内容类型.请注意MIME类型如何以+xml结尾,并且按照 RFC 3023 ,XML处理器(包括XMLHttpRequest)就可以像处理XML一样处理此类表示形式."同一家银行也可能使用XML表示银行转帐,这一次使用Content-Type application/vnd.bank.org.transer+xml

As an example (taken from this excellent article that is worth reading in full), a Bank may want to define a Content-Type for bank accounts of application/vnd.bank.org.account+xml. Note how the MIME type "ends with +xml, and as per RFC 3023, XML processors (including XMLHttpRequest) can handle such representations as though it is XML". The same bank might also use XML to represent a bank transfer, this time using a Content-Type of application/vnd.bank.org.transer+xml

这篇关于REST-Web服务响应-MIME类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆