How to use Both GET and POST Methods in one Request

Get and Post Methods

Because you are reading this, it tells me that you have somewhat wondered whether or what will happen should you want to use both GET and POST methods in your server requests.

This is not typically taught in you run-off the mill web design course and that could play out as to why this could be a question in your mind whether or not you are new to the web development game.

Well, whenever a request is made from a web browser to a web server, there are a couple of unseen bits of data that is passed from the web browser to the server.

Depending on what you are doing this could be one or a combination of COOKIE, GET, and POST variables. Normally you do not control the passing of cookies as the casual website visitor but you may have more influence over the GET and POST methods based on your actions in the point in time.

As the web developer, you have the complete control as to how you handle these variables and create an experience for your users.

When Should you use GET and POST Methods?

GET is usually ideal for passing non-sensitive information back to the server. This could be parameters that control which page or what parts of a page to load.

Read Also  How to Configure mod_security With Apache on Debian/Ubuntu or CentOS

GET is also ideal for smaller amounts of data. A good cap would be about 1025 characters. It is also good to know that browsers have a limit as to how much data can be sent via GET and POST methods.

POST is usually good for handling lots of data that needs to be sent to the server as well as sensitive information that should not be visible to prying

This data includes multi-part data collected through HTML forms such as emails and their attachments, login and registration forms etc.

How About if you Want to use Both in one Action?

There is no restrictions on combining the methods, this is more of a design issue than a technical one. Here we will show you the solution using a simple HTML form and using JavaScript to process the form.

When creating an HTML form you may set some attributes. These are the ACTION and the METHOD attributes. You must set the METHOD to “POST” to pass the form inputs as POST data.

To use the GET method, you then need to add the GET data directly as a query string in the ACTION parameter and it is as simple as that.

Read Also  The New CUDA 8 Toolkit Release Candidate Now Available

The above is an example of a form which submits data using both the GET and POST methods.