HTTP PUT的替代主体 [英] Alternative bodies for HTTP PUT

查看:89
本文介绍了HTTP PUT的替代主体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个REST-ful网络服务,我对HTTP PUT方法有疑问。

I'm developing a REST-ful webservice, and I have a question about the HTTP PUT method.

我想允许人们使用应用程序提交内容/ form-data请求体。但是,默认响应将在application / xml中。

I want to allow people to submit content using a application/form-data request body. However, the default response will be in application/xml.

这可以接受吗?

Evert

推荐答案

内容类型只在范围内很重要一个请求。他们所做的只是描述正在发送的内容的格式。

Content types are only important within the scope of a single request. All they do is describe the format of the content that is being sent.

您的Web服务应提供其能够提供的客户端请求最可接受的响应。客户端请求应包含描述可接受内容类型的Accept标头。如果您的服务无法在此标题中提供任何内容类型,则返回 406不可接受

Your web service should provide the response most acceptable to the client request that it is capable of providing. The client request should include an Accept header that describes the acceptable content types. If your service can't provide any of the content types in this header then return 406 Not Acceptable

在您的情况,如果您的客户 GET 请求在Accept标头中包含 application / xml ,那么可以用<$回复c $ c> application / xml ,无论在请求的资源上发出任何 PUT 请求。

In your situation, if your client GET requests include application/xml in the Accept header then it is fine to respond with application/xml, regardless of any PUT request made on the requested resources.

编辑:

406的rel =nofollow noreferrer>状态代码定义不可接受包含以下注释:

The status code definition for 406 Not Acceptable includes a note with the following:


注意:根据
请求中发送的接受标头,允许HTTP / 1.1服务器返回
不可接受的响应。在某些情况下,这可能比发送
406响应更可取。我们鼓励用户代理检查传入响应的
标题以确定它是否可接受。

Note: HTTP/1.1 servers are allowed to return responses which are not acceptable according to the accept headers sent in the request. In some cases, this may even be preferable to sending a 406 response. User agents are encouraged to inspect the headers of an incoming response to determine if it is acceptable.

所以你可以返回 application / xml 随时随地。

So you can return application/xml whenever you want.

这篇关于HTTP PUT的替代主体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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