content-type in request and response

We will often see the content-type attribute in http.

The content-type attribute has this attribute in the HTTP request header and response header.

Generally, we use chrome to access a url, such as http://www.baidu.com

You can see that the Response headers have the following properties, note that the request headers have no content-Type

  1. Connection:
    keep-alive
  2. Content-Encoding:
    gzip
  3. Content-Type:
    text/html; charset=utf-8
  4. The Content-Type here means that the returned result is text/html, and the browser can display the content correctly according to this attribute.
  5. If you visit a picture such as //www.baidu.com/img/bd_logo1.png
  6. Content-Type:
    image/png, you can look at the response, it is some incomprehensible data, in fact, the network transmission is a binary file,
  7. The browser first decodes the binary file into a character file. If the content-type is text/html, the browser will parse the response interface format according to the html specification. If it is image/png, parse the response as an image.
  8. Generally, most of the content-type you arrive at Baidu refers to the content-type of the response headers, which is not comprehensive.

Look at the content-type of the request headers. This format generally includes multipart/form-data, application/x-www-form-urlencoded, application/json,

Among them, application/x-www-form-urlencoded is the default value for form submission. For get and post requests, browsers will process the request data parameters differently. Multipart/form-data is mainly used for file uploading. And application/json is used more now, and the parameters are directly passed to the server in json format. In the java code, the server obtains it through request.getInputStream, and application/json can also be used for response headers, telling the client that this is a Data in json format, most restful apis are in this format.

 

 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327041363&siteId=291194637