Android http Request/Response ContentType, androidcontenttype

Source: Internet
Author: User

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 ");

  

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.