Content types

HTTP can be used as a method of transport for any type of file or data. The server can use the 'Content-Type' header in a response to inform the client about the type of data that it has sent in the body. This is the primary means with which an HTTP client determines how it should handle the body data that the server returns to it. To view the content type, we inspect the value of the response header, as shown here:

>>> response = urlopen('http://www.debian.org')
>>> response.getheader('Content-Type')
'text/html'

These values are called content types, internet media types, or MIME types. The full list can be found at http://www.iana.org/assignments/media-types.

Content type values can contain optional additional parameters that provide further information about the type. This is usually used to supply the character set that the data uses; for example, Content-Type: text/html; charset=utf-8.

In this screenshot, we can see many Content-Type instances depending on the requested URL:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset