Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between HttpMethod and RequestType of HttpRequest?

The HttpRequest class defines two properties:

HttpMethod:

Gets the HTTP data transfer method (such as GET, POST, or HEAD) used by the client.

public string HttpMethod { get; }  

The HTTP data transfer method used by the client.

and RequestType:

Gets or sets the HTTP data transfer method (GET or POST) used by the client.

public string RequestType { get; set; }

A string representing the HTTP invocation type sent by the client.

What is the difference between these two properties? When would I want to use one over the other? Which is the proper one to inspect to see what data transfer method was used by the client?

The documentation indicates that HttpMethod will return whatever verb was used:

such as GET, POST, or HEAD

while the documentation on RequestType seems to indicate only one of two possible values:

GET or POST


I tested with a random sampling of verbs, and both properties seem to support all verbs, and both return the same values:

Testing:

Client Used    HttpMethod    RequestType
GET            GET           GET
POST           POST          POST
HEAD           HEAD          HEAD
CONNECT        CONNECT       CONNECT
MKCOL          MKCOL         MKCOL
PUT            PUT           PUT
FOOTEST        FOOTEST       FOOTEST

What is the difference between:

  • HttpRequest.HttpMethod
  • HttpRequest.RequestType

and when should I use one over the other?

like image 587
Ian Boyd Avatar asked Sep 08 '25 15:09

Ian Boyd


1 Answers

Reflector shows that RequestType calls HttpMethod internally. So you're ever so slightly better off calling HttpMethod. Actually I think the real reason RequestType exists was for backwards compatibility with classic ASP.

like image 78
Duncan Smart Avatar answered Sep 10 '25 05:09

Duncan Smart