The HttpRequest class defines two properties:
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?
Reflector shows that
RequestTypecallsHttpMethodinternally. So you’re ever so slightly better off callingHttpMethod. Actually I think the real reasonRequestTypeexists was for backwards compatibility with classic ASP.