difference between http get and post

what are difference between http post and get, as far as what/how data is passed in a http request.
Reason I'm asking is, I created a simple ASP.NET MVC application. I have two methods (shown below, example contrived for this question). one method is decorated with [HttpPost] and other one is not. when i make a call from a third party app, it hits the break point in the first function ProcessData1 and I get the id parameter as well, since it is being passed in query string.
but if i try to make a call to ProcessData2, it doesn't hit the break point in that function.
I know the third party application, I'm using is making a Http post call.
I tried another rest client and this time when I made a call to ProcessData2, it was successful.

can some one point out possible reasons?

        public ActionResult ProcessData1(string id) {          
            return View(request);
        }

       [HttpPost]
        public ActionResult ProcessData2() {          
            return View(request);
        }
novice programmerAsked:
Who is Participating?
 
nociSoftware EngineerCommented:
an HTTP GET is a request for data , the request is on the first line in the packet after GET  (<protocol:>//[user[:password]@][host][:port]/URI
it starts with the /.
the protocol part is parsed away (the method is used to make the connection)
the user:password are optional and if provided they are placed in the header on a later line.
The hostname is provided in the header on a later line and a translation is used to connect to the host on the port mentioned or the default for the protocol. Anything after that in on the line.
The content part of the GET query is empty.
In the answer the content of the HTTP packet contains the data the host wanted to send.  In classical sense the contents of the requested file.

The real opposite of the GET is a PUT (put a file on the server...)    but that is not often used.
Instead a POST is used. The result is that data is sent to the host with the URI on the first line (like in the GET).
The contents of the packet contains all data (tail after the header).
The server will run a script as response to a POST, and will either hand over the content part as is, or even split it in "fields" and feed the named fields to the script that is run.
if you want to experiment with it the cURL tool is very handy (from: haxx.se)
1
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
Do you get the same with SoapUI?
https://www.soapui.org/
0
 
novice programmerAuthor Commented:
thanks @noci - for the explanation. I also read today that "in get request, the data is sent in the query string and in post it is sent in the form values".

so i guess, when the request hits the server method, the get request is in format below

http://localhost/somemethod?id=4&name=demo. I am using ASP.NET to learn concepts of this, I have a controller method as below. so when tested, the id and name value in the query string are mapped to corresponding parameters in my controller method.
this is where the model binding comes in, I think right?
so based on this , how would one read or get data for the HTTP post call?

public somemethod(string id, string name){
}
0
 
nociSoftware EngineerCommented:
yes you are correct.
In most cases both ways of delivering are processed by standard libraries, which will parse the data in name/value pairs and pass those to the programs.
.NET is not my cup of tea, but PHP provide name value pairs . Perl has a library to convert the CGI parameters into name/value pairs. etc.
Both PHP and Perl + Library can handle both forms on input and will provide name value pairs.
(even for posted files (ie. File upload)...).  (in that case it is just a BIG field..)
0
 
novice programmerAuthor Commented:
@noci - thanks for your explanation. I'm going to post another question under asp.net mvc.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.