GET and POST, GETPOST
The types of HTTP requests include GET, POST, PUT, DELETE, OPTIONS, TRACE, and so on. GET and POST are commonly used. The differences are as follows:
1. The GET method is used to retrieve data from the server, and the POST method is used to submit data to the server.
2. Use the GET method to submit a small amount of data to the server, which generally does not exceed 2 K. However, there is usually no limit on the amount of data submitted to the server using POST.
3. a GET request attaches the data to the URL, while a POST request places the submitted data in the Request body.
First, build a local tomcat server
1. Download To http://tomcat.apache.org and decompress to a directory (cannot be empty or Chinese)
2. Configure the environment variable: JAVA_HOME; Value: C: \ Program Files \ Java \ jdk1.8.0 _ 25
3. Run startup. bat in the bin directory of tomcat and access http: // IP: 8088.
Add a file to the ROOT directory for testing. The content is as follows:
<% String name = request. getParameter ("name"); String pwd = request. getParameter ("password"); out. print ("name:" + name + ", password:" + pwd); %>
The preceding steps use the Get method to submit data to the server. Only the request header has no request body and the data volume is limited. Instead, use the POST method to submit data to the server. The steps are as follows:
1. Construct a request object
2. Place the data to be passed to the server in the key-Value Pair object NameValuePair.
3. Store the key-Value Pair object in the List.
4. Generate a request body object
5. Place the List object in the Request body object
6. Place the Request body object in the request object
7. Send the request object and process the response data in a similar way as the get method.