简体   繁体   English

我应该为 HTTP PUT 使用什么编码?

[英]What encoding should I use for an HTTP PUT?

I am writing a webserver.我正在写一个网络服务器。 I implemented GET and POST (application/x-www-form-urlencoded, multipart/form-data) and that works fine.我实现了 GET 和 POST(应用程序/x-www-form-urlencoded,multipart/form-data)并且效果很好。

I am thinking of adding a RESTful module to the server.我正在考虑向服务器添加一个 RESTful 模块。 So had a look at some stuff that's out there and got opinions about when to PUT, POST, and GET.所以看看那里的一些东西,并获得关于何时 PUT、POST 和 GET 的意见。

My question is: what encoding (application/x-www-form-urlencoded, multipart/form-data) does PUT support (per the HTTP specifications), or can it handle both?我的问题是:PUT 支持什么编码(应用程序/x-www-form-urlencoded,multipart/form-data)(根据 HTTP 规范),还是可以同时处理这两者?

I am trying to make the webserver as standard specific as I can without shooting myself in the foot.我正在尝试使网络服务器尽可能地成为标准特定的,而不会自欺欺人。

HTTP PUT can have whatever content-type the user wishes (the same as for all other HTTP methods). HTTP PUT 可以具有用户希望的任何内容类型(与所有其他 HTTP 方法相同)。

The limitation to application/x-www-form-urlencoded and multipart/form-data is not in the HTTP standard but in HTML. application/x-www-form-urlencoded 和 multipart/form-data 的限制不在 HTTP 标准中,而是在 HTML 中。 It's the only formats that can be created by an HTML form.它是唯一可以由 HTML 表单创建的格式。 From HTTP point of view, you can use any format, as long as you specify it to the server ( Content-Type header) and obviously that the server can understand it.从HTTP来看,你可以使用任何格式,只要你指定给服务器( Content-Type header)并且显然服务器可以理解。 If not, it reply with a 415 Unsupported Media Type status code.如果不是,它会回复415 Unsupported Media Type状态码。 See:看:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM