Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTTP post: url parameters and form data

Tags:

When I do http POST request via Web form, Is there any difference(practically or theoretically) between parameters specified in the URL and parameters passed with form on the server side?

Can I do whole POST with url parameters and expect same result as with form inputs?

Like:

  <form action="/?id=2" method="post">
      <input type="text" name="name" value="John"/>
      <input type="submit" value="submit"/>
  </form>

Or:

  <form action="/?id=2&name=John" method="post">
      <input type="submit" value="submit"/>
  </form>

Thanks.

like image 663
Bogdan Gusiev Avatar asked Oct 23 '10 17:10

Bogdan Gusiev


People also ask

Can we pass URL parameters in POST request?

In a GET request, the parameters are sent as part of the URL. In a POST request, the parameters are sent as a body of the request, after the headers. To do a POST with HttpURLConnection, you need to write the parameters to the connection after you have opened the connection.

How can we POST form data using URL?

The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute). The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs.

Can we GET data from HTTP POST?

HTTP POST requests supply additional data from the client (browser) to the server in the message body. In contrast, GET requests include all required data in the URL. Forms in HTML can use either method by specifying method="POST" or method="GET" (default) in the <form> element.

What is form data in POST request?

Short answer: in POST requests, values are sent in the "body" of the request. With web-forms they are most likely sent with a media type of application/x-www-form-urlencoded or multipart/form-data .


2 Answers

The references Gabriel and BrokenGlass provided are really cool, but let me give you me 2 cents.

I'm supposing you already know a little about how to retrieve data sent from the form on the server-side. If you don't, start there and the answers will come faster than you could imagine.

Well, parameters sent on the URL or the form's attribute action are GET data parameters. They will be parsed and made available as such. Period.

The input fields from a form with method POST are sent as POST data and are parsed and available as such.

From examples you gave, and supposing you are using PHP, we could retrieve the following:

Example 1

$_GET['id']
$_POST['name']

Example 2

$_GET['id']
$_GET['name']

Hope the concepts are clear.

like image 180
Davis Peixoto Avatar answered Sep 28 '22 10:09

Davis Peixoto


You should read this article on the differences between GET and POST (GET is when you put your parameters in the URL, and POST is when you put your parameters in the form).

Also, this question has already been answered here on StackOverflow

like image 35
Gabriel McAdams Avatar answered Sep 28 '22 11:09

Gabriel McAdams