1, concept,

Content-Type represents the Content Type and character encoding. Content types are also called MIME types. It's Internet Media Type. Data transmitted over the Internet has different data types, and HTTP distinguishes data objects by labeling them with a data format called MIME. The Content-Type in the request header is the description of the data type sent from side B to side S. That is to tell the server side, I send you a certain type of data, the server side for different types of data, the way is different. For example, we usually deal with people, pigs, dogs and other different types of animals in different ways. When you meet a dog, you have to "wow wow" and when you meet a person, you have to say "hello". The Content-Type in the response header is the description of the data type sent by S end to B end. It tells the browser what format I'm sending you, and the browser handles it differently for different types of data. 2. Syntax format, whether it appears in the request header or the response header, is a key-value pair. Content-type: value, e.g. Content-type: text/ HTML; Charset = utf-8. Content-type: text/ HTML; Content-type: text/ HTML; Content-type: text/ HTML; Charset = utf-8. The content that my server sends to you in response is in HTML format, and the character set is UTF-8. The Content-Type in the request header can be seen in the Chrome browser's network.

1

1) Application /x-www-form-urlencoded, application/x-www-form-urlencoded, application/x-www-form-urlencoded, application/x-www-form-urlencoded, application/x-www-form-urlencoded, application/x-www-form-urlencoded, application/x-www-form-urlencoded, application/x-www-form-urlencoded, application/x-www-form-urlencoded The value of Content-Type in the request header is application/x-www-form-urlencoded. At the same time, the browser automatically organizes the contents of the form elements inside the form tag into key-value pairs (key1=val1&key2=val2). Where the key is the value of the name attribute of each form element; The value is the value of the value attribute of the form element. The key and value are transcoded into the URL. And put it inside the request entity. (Note that if it is Chinese or special characters such as "/",","," :", etc., URL transcoding will be automatically carried out.) Game code examples are as follows:

2

If you use Ajax to send a POST request, use www.diuxie.com setRequestHeader(); Set the content-type. XMLHttpRequest object.setRequestHeader(" Content-Type "," Application/X-WWW-form-urlencoded "); 2) multipart/form-data This is commonly used when uploading files. Entry ="multipart/form-data". The Content-Type in the request header is multipart/form-data. The Content-Type in the request header is multipart/form-data. A boundary = - WebKitFormBoundarybi5XUwMxC7yc9s5a. You can upload binary data, such as files, as well as form key-value pairs, only to end up with a message. Sample code:

3

3) Application/JSON This format (JSON format) is currently the most used in front-end separation development scenarios. The data interaction between the front and back ends is carried out in JSON format, which is easy to read, brief and convenient. This format is typically used when sending Ajax requests, or when the content-type is explicitly set to application/json. Alternatively, some third-party libraries default to application/json. Here is the sample code: the XMLHttpRequest object.setRequestHeader(" Content-Type ","application/json"); 4) Text/XML This format (XML format) is the older format. It's used less because XML data is bigger and more complex than JSON data. So, basically eliminated. The Content-Type in the response header can be seen in the network of the Chrome browser.

4. Code sources that exist in games:

This can be set through the response object on the back end, as in PHP:;

5

5. Content-type application/json is commonly used in front and back end interactions. Whether the front end sends data to the back end or the back end sends data to the front end, the most common type is application/json. This is the introduction of Content-Type. I hope it can help you.