Why HttpRequest.HttpMethod is string instead of Enum?

后端 未结 4 1923
没有蜡笔的小新
没有蜡笔的小新 2020-12-17 08:36

In the Reference of HttpRequest.HttpMethod of .NET Framework, request type is declared with System.String type.

In RFC 2616 all HTTP request methods are

4条回答
  •  佛祖请我去吃肉
    2020-12-17 09:18

    As Damien mentions, RFC2616 only defines the common methods. HTTP, like XML, is a protocol that can be extended to support other formats.

    For instance, suppose I wanted to implement a special method called "Encrypt". If the HTTP library were enums, it would fail and likely throw an exception. Of course the client would have to know about this special request type, which is why most extensions are done via headers rather than commands.

    HTTP is an extensible protocol, but few people actually do extend it.

    Consider this simple example:

    Since "method" is just text, and the user could put anything there, then the HTTP handler has to be able to handle it, correct?

    EDIT:

    As it turns out, the HTML 4 specification only allows for GET and POST to be valid values, but HTTP goes beyond that.

提交回复
热议问题