Home > Mobile >  What is the difference between a HTTP Request and a HTTP GET/POST request?
What is the difference between a HTTP Request and a HTTP GET/POST request?

Time:09-20

For start - I understand the difference between GET and POST.

What I don't understand is how does a request that doesn't mention either of them work, when and why would I want to use it?

Here's an example from ASP.NET Docs:

Map method

MapGet method

MapPost method

CodePudding user response:

HTTP requests always have an HTTP method associated with them. GET and POST are two such methods, but there are others (see here).

When you call the MapGet, MapPost, or Map methods, you are creating "rules" that ASP.NET will use to route incoming requests to different parts of your application code, depending on which rules are matched.

Part of each rule is the route pattern itself, but you can also require a specific HTTP method in order for a rule to be matched. That's what MapGet and MapPost are doing - when you use them, they will only match requests that also have the appropriate HTTP method (GET and POST, respectively). In contrast, Map will match any incoming request (that also matches the route pattern), regardless of the HTTP method of the request.

This can be an easy way to get your application to behave differently depending on the HTTP method that is used. For example, you could use MapGet to route GET requests to a method that will return something, while using MapPost to route POST requests to a method that will create a new record. If you want your application to behave the same way for all requests (or you want to programmatically check the request method), you could just use Map.

  • Related