Web server basics

Simulate web server

  • Understand what is get and host?

Get: Request the specified page information and return the entity body.

Host: Submit data to the specified resource for processing request (such as submitting a form or uploading a file). The data is contained in the request body. POST requests may result in the creation of new resources and/or the modification of existing resources.

​ The difference between the two:

  1. GET is generally used to obtain/query resource information, and POST is generally used to update resource information.
  2. The data submitted by GET will be placed after the URL. Separate the URL and transmit the data with ?. The parameters are connected by &, such as EditPosts.aspx? name=test1&id=123456. The POST method is to put the submitted data in the body of the HTTP package. .
  3. The size of the data submitted by GET is limited (because the browser has limitations on the length of the URL), while the data submitted by the POST method is not limited.
  4. GET method needs to use Request.QueryString to get the value of the variable, while POST method uses Request.Form to get the value of the variable.
  5. Submitting data via GET will bring security issues. For example, when submitting data via GET, the user name and password will appear on the URL. If the page can be cached or other people can access the machine, you can view the history Record the account and password of the user.
  • Identify what is a request, what is a response, and the elements that make up them?

Request: The request message sent by the client to the server, we call it a request, which is actually a string concatenated according to the rules of the http protocol. The Request request message contains three parts: request line message header request body

  1. Request line

    1. 格式:
      Method Request-URI HTTP-Version CRLF

    2. Method indicates the request method; generally GET or POST; Request-URI is a uniform resource identifier; HTTP-Version indicates the requested HTTP protocol version; CRLF indicates carriage return and line feed

    3. For example: GET /test.html HTTP/1.1 requests a test.HTML resource from the server through the http1.1 protocol

  2. Message header http header

    1. Pass: some connected information similar to key-value pairs

    2.    GET /test.html HTTP/1.1 
         Host: 127.0.0.1:9999 
         User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
         Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
         Accept-Language: zh-CN,en;q=0.8,zh;q=0.5,en-US;q=0.3 
         Accept-Encoding: gzip, deflate 
         Connection: keep-alive 
      
  3. Request body http body

    1. There is a blank line between the request header and the request body . This line is very important. It indicates that the request header has ended, and the next is the request body. The request body can contain string information submitted by the customer

    2. Note: There is a blank line between the second part header and the third part body, unless there is no request body

Response: After the server receives and interprets the client's request message, the server will return an HTTP response message to the client, which we call a response (response). In fact, it is also a string that is spliced ​​according to the rules of the http protocol. The
HTTP response is also composed of three parts, namely: response status line, message header, and response body

  1. Response status line

    1. HTTP-Version Status-Code Reason-Phrase CRLF
    2. HTTP/1.1 200 OK
    3. HTTP-Version indicates the server HTTP protocol version;
      Status-Code indicates the response status code sent back by the server;
      Reason-Phrase indicates the text description of the status code.
      CRLF means carriage return and line feed
  2. Message header

    1. HTTP message headers include four categories: ordinary header, request header, response header, and entity header.

    2. Expressed by the attribute Content-Type in the response message header

    3. ("png", "image/png;charset=utf-8");
      ("pdf", "application/pdf;charset=utf-8");
      ("html", "text/html;charset=utf-8");
      ("txt", "text/html;charset=utf-8");
      "Content-Type: text/html;charset=utf-8\r\n"
      
  3. Response body

    1. The response body is the content of the resource returned by the server
  • How to deploy a project on Ubuntu?

First type the project into a jar package

Then deploy the resource files and jar packages to the virtual machine using the remote control tool

Then open the server in the virtual machine java -jar server.jar

You can get resources in this machine through ip address and port number and get/host request

Guess you like

Origin blog.csdn.net/xiaole060901/article/details/108560000