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:
and when should I use one over the other?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With