Android http Request/Response ContentType, androidcontenttype
When the client sends an http request to the server, it must tell the server the type of the request. When the server returns data to the client, it also needs to tell the client the type of the returned data.
This type is ContentType. Different contenttypes will affect the effect seen by the Client/Server. ContentType: Tell the server what type of data to send
1. The default ContentType is text/html, that is, the webpage format.
- Text/plain: plain text format
- Text/xml: XML format
- Image/gif: gif image format
- Image/jpeg: jpg image format
- Image/png: png image Format
Media format type starting with application:
- Application/xhtml + xml: XHTML format
- Application/xml: XML data format
- Application/atom + xml: Atom XML aggregation format
- Application/json: JSON Data Format
- Application/pdf: pdf Format
- Application/msword: Word Document Format
- Application/octet-stream: binary stream data (such as common file downloads)
- Application/x-www-form-urlencoded: <form encType = ""> default encType, form data is encoded as the key/value format and sent to the server (the default format of form data submission)
Another common media format is used when uploading files:
- Multipart/form-data: This format is required when you need to upload files in the form.
The above are some content-type formats that we often use in daily development.
For example:
URL realUrl = new URL (url); // connection between opening and URL conn = realUrl. openConnection (); // set the common request attribute conn. setRequestProperty ("accept", "*/*"); conn. setRequestProperty ("connection", "Keep-Alive"); conn. setRequestProperty ("Content-Type", "application/json ");