Http get post request)

Source: Internet
Author: User

The get and post methods in form correspond to the get and post methods in the HTTP protocol during data transmission. The main differences between the two are as follows:
1. Get is used to obtain data from the server, while post is used to transmit data to the server.

2. Get adds the data in the form to the URL pointed to by action in the form of variable = value, and the two use "?" And each variable is connected by "&". Post puts the data in the form data body and passes the data to the URL indicated by the action according to the corresponding variables and values.

3. Get is insecure because data is stored in the request URL during transmission, nowadays, many existing servers, proxy servers, or user proxies record the request URL to a log file and place it in a certain place, so that some private information may be seen by a third party. In addition, you can directly view the submitted data in the browser. Some internal messages are displayed in front of the user. All post operations are invisible to users.

4. Get transmission has a small amount of data, mainly because it is limited by the URL Length (2048 bytes), while post can transmit a large amount of data, therefore, only post can be used to upload files (of course, there is another reason, which will be mentioned later ).

5. Get restricts that the dataset value of form forms must be ASCII characters, while post supports the entire iso000046 character set.

6. Get is the default form method.

 

 

 

Accept the end of the post request. To make it easier for everyone to understand, act as a server. The above code is better as a client. On the server side, we need to write a servlet. this servlet is started immediately after the server is started. This is configured in the web. xml file. I think everyone will. The server code is as follows:

Import java. Io. ioexception;
Import javax. servlet. servletexception;

 

Import javax. servlet. http. httpservlet;
Import javax. servlet. http. httpservletrequest;
Import javax. servlet. http. httpservletresponse;
/**
* Servlet implementation class getrequestservlet
*/
Public class getrequestservlet extends httpservlet {
Private Static final long serialversionuid = 1l;
// Private Static final logger log = logger. getlogger (getrequestservlet. Class );
/**
* @ See httpservlet # httpservlet ()
*/
Public getrequestservlet (){
Super ();
// Todo auto-generated constructor stub
}
/**
* @ See httpservlet # doget (httpservletrequest request, httpservletresponse response)
*/
Protected void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
String file = request. getparameter ("file ");
String sendtimestr = request. getparameter ("sendtime ");
Long sendtime = long. valueof (sendtimestr );
Response. setcontenttype ("text/html; charset = UTF-8 ");
System. Out. println (File );
System. Out. println ("current time used for sending and receiving Slave Data:" + (system. currenttimemillis ()-sendtime ));
// Printwriter out = response. getwriter ();
// Out. println ("Hello world! "+ File );
}
/**
* @ See httpservlet # dopost (httpservletrequest request, httpservletresponse response)
*/
Protected void dopost (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {
Doget (request, response );
}
}

 

If the file to be read is not large, you can deliver the file stream to the server. However, once the file grows, an error occurs. This may be because the content size of the post suffix is limited. I think so. If there is an error, correct it.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.