20

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.

Bogdan Gusiev
  • 7,447
  • 14
  • 59
  • 76
  • 1
    your answer is in this post: http://stackoverflow.com/questions/611906/http-post-with-url-query-parameters-good-idea-or-not/612022#612022 – BrokenGlass Oct 23 '10 at 18:00

2 Answers2

16

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.

Wilson Canda
  • 432
  • 4
  • 18
Davis Peixoto
  • 5,273
  • 2
  • 21
  • 33
  • +1 - many sites don't care whether parameters arrive in the query string or request body (e.g. anything that uses on Java's HttpServletRequest.getParameter() or PHP's $_REQUEST), but it's *possible* to distinguish - therefore you can't *expect* the same behaviour in the general case. It may well work for a given site, though. – SimonJ Oct 23 '10 at 18:56
  • Yeap, that's true. This is why I made some considerations on examples. For general case, even cookies are an extension on HTTP protocol and can be accessed via general request resources. But for sake of clearness on this subject I think we should get down on the specifications. GET and POST are distint methods due distint purposes (along other methods like HEAD, PUT, DELETE...). Each HTTP method has it's own purpose, and all software in the middle process (like HTTP server) may have different ways to thread them (and data wrapped in each one). – Davis Peixoto Oct 23 '10 at 19:38
1

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

Community
  • 1
  • 1
Gabriel McAdams
  • 51,587
  • 10
  • 58
  • 76