Total Page Preview: 000000000340
What are HttpGet and HttpPost Method in Asp.Net Core MVC in English and hindi
HttpGet and HttpPost Method in English
HttpGet and HttpPost, both are the method of posting client data or form data to the server. HTTP is a HyperText Transfer Protocol that is designed to send and receive data between client and server using web pages. HTTP has two methods that are used for posting data from web pages to the server. These two methods are HttpGet and HttpPost.
HTTPGET
HttpGet method sends data using a query string. The data is attached to URL and it is visible to all the users. However, it is not secure but it is fast and quick. It is mostly used when you are not posting any sensitive data to the server like username, password, credit card info etc.
Some Fact about HttpGet Method
-
It is fast and quick but not secure.
-
It is default method.
-
Because it attached form data in query string, so the data is visible to other users.
-
It uses stack method for passing form variable.
-
Data is limited to max length of query string.
-
It is very useful when data is not sensitive.
-
It creates URL that is easily readable.
-
It can carry only text data.
Example
When you will run the application and pass value using HttpGet method, you will see that data is attached to URL using Query String.
http://localhost:2709/Home/Submit?Id=1&Name=Diablo
In this previous link, the data is passed using query string because submit button used HttpGet Method to post data. You can see that Id=1&Name=Diablo in URL.
Output Image
HTTPPOST
HTTPPost method hides information from URL and does not bind data to URL. It is more secure than HttpGet method but it is slower than HttpGet. It is only useful when you are passing sensitive information to the server.
Some Fact about HttpPost Method
-
Data is sent via HttpPost method, is not visible to user.
-
It is more secured but slower than HttpGet.
-
It uses Heap method for passing form variable.
-
It has no restriction of passing data and can post unlimited form variables.
-
It is used when sending critical data.
-
It can carry both text and binary data.
Example
Look at this URL structure. You will notice that there is no data attached to the URL.
http://localhost:2709/Home/Submit
Output
Difference between HttpGet and HttpPost Method
1. HTTPGet method is default whereas you need to specify HTTPPost attribute if you are posting data using HTTPPost method.
2. HTTPGet method creates a query string of the name-value pair whereas HTTPPost method passes the name and value pairs in the body of the HTTP request.
3. HTTPGet request has limited length and mostly it is limited to 255 characters long whereas HTTPPost request has no maximum limit.
4. HTTPGet is comparatively faster than HTTPPost. HTTPPost takes extra time in encapsulating the data.
5. HTTPGet can carry only string data whereas HTTPPost can carry both string and binary data.
6. HTTPGet method creates readable url so it can be cached and bookmarked whereas such facility is not available in HTTPPost method.
HttpGet and HttpPost Method in Hindi
HTTP GET aur HTTP POST, ASP.NET Core MVC (Model-View-Controller) mein istemal hone wale do pramukh HTTP request methods hain, jo client aur server ke beech communication mein istemal hote hain. In dono methods ka istemal alag-alag prakar ke server-side operations ke liye hota hai.
HTTP GET Method:
-
GET method, server se data retrieve karne ke liye istemal hota hai.
-
URL ke madhyam se query parameters ko server tak pahunchane mein istemal hota hai. Example: /products?id=1.
-
GET request URL mein query string parameters ke saath hota hai, jinke values URL ke hisse mei hote hain.
-
GET request idempotent hota hai, yani ki bar-bar GET request bhejne se koi side-effect nahi hota.
-
ASP.NET Core MVC mein, GET requests ke liye Controller action methods define kiye ja sakte hain, jinhe routing ke sath map kiya jata hai.
HTTP POST Method:
-
POST method, server par data submit karne ke liye istemal hota hai.
-
POST request ke body mein data hota hai, jo server ke liye naye resource create karne ya existing resource ko update karne ke liye istemal hota hai.
-
POST request non-idempotent hota hai, yani ki bar-bar POST request bhejne se side-effects ho sakte hain.
-
ASP.NET Core MVC mein, POST requests ke liye Controller action methods define kiye ja sakte hain, jo HTTP POST verb ke sath map kiye jate hain.
ASP.NET Core MVC mein, Controller action methods HTTP request methods ke sath map kiye jate hain. Niche ek example hai:
Is example mein, GetProduct ek GET request ke liye action method hai aur CreateProduct ek POST request ke liye action method hai. HttpPost attribute se ye indicate kiya jata hai ki ye action method POST request ko handle karega.
Thank You
About Author
Brijesh Kumar
Database Developer
I have more then 6 years Experience in Microsoft Technologies - SQL Server Database, ETL
Azure Cloud - Azure SQL Database, CosmosDB, Azure Data Factory, PowerBI, Web Job, Azure Function, Azure Storage, Web Apps, Powershall
and Database Migration On-Premise to Azure Cloud.
LinkedIn : https://www.linkedin.com