Components of the request:
-
Request header
-
Request line
-
Blank line
-
Body
Request line = http protocol version + httpURL + submission method
Request submission method
-
-
Enter the URL in the address on the browser and press Enter
-
Hyperlink submission method
-
Method = "get" in the form, if there is no method, the default get is submitted
-
-
post submission
-
In the form method = "post"
-
Basically use the post submission method in the form
Difference between post / get submission method
feature | get method | post method |
---|---|---|
Submit data type | text | Text, binary |
Submit data length | <255 characters | Unlimited |
Visibility of submitted data | Display as part of URL address | The requested message body is not visible |
Cache of submitted data | Cached in browser URL history cache | You will cache in your browser |
Request method
// Request line information // Get the version of the content submission method url http // Submission method String method = req.getMethod (); // url String uri = req.getRequestURI (); // http version String http_version = req.getProtocol (); // Get query string String queryString = req.getQueryString (); // Decode queryString String new_queryString = URLDecoder.decode (queryString, "utf-8" ); // Get the path of the web application String contextPath = req.getContextPath (); // Get the URL path of access: protocol + ip + port number + uri StringBuffer url = req.getRequestURL (); // Get the servlet path String servletPath = req.getServletPath (); // Get the requested character encoding set String encoding = req.getCharacterEncoding (); // Get the visitor's ip address ( *********) String ipaddress = req.getRemoteAddr (); // Request header information // Get the information of the specified header- > String req.getHeader ("Header name" ); // Common Header name // Referer-> get the sending URL of the request (the anti-theft chain can be implemented) // User-Agent-> get the browser information (for example: version ...) // Cookie-> get the browser drawing information // Get the names of all the heads-> Enumeration req.getHeaderNames();