zoukankan      html  css  js  c++  java
  • Media Formatters in ASP.NET Web API 2

    This tutorial shows how to support additional media formats in ASP.NET Web API.

    Internet Media Types

    A media type, also called a MIME type, identifies the format of a piece of data. In HTTP, media types describe the format of the message body. A media type consists of two strings, a type and a subtype. For example:

    • text/html
    • image/png
    • application/json

    When an HTTP message contains an entity-body, the Content-Type header specifies the format of the message body. This tells the receiver how to parse the contents of the message body.

    For example, if an HTTP response contains a PNG image, the response might have the following headers.

    HTTP/1.1 200 OK
    Content-Length: 95267
    Content-Type: image/png

    When the client sends a request message, it can include an Accept header. The Accept header tells the server which media type(s) the client wants from the server. For example:

    Accept: text/html,application/xhtml+xml,application/xml

    This header tells the server that the client wants either HTML, XHTML, or XML.

    The media type determines how Web API serializes and deserializes the HTTP message body. Web API has built-in support for XML, JSON, BSON, and form-urlencoded data, and you can support additional media types by writing a media formatter.

    To create a media formatter, derive from one of these classes:

    Deriving from BufferedMediaTypeFormatter is simpler, because there is no asynchronous code, but it also means the calling thread can block during I/O.

     

     

  • 相关阅读:
    HDU 5528 Count a * b 欧拉函数
    HDU 5534 Partial Tree 完全背包
    HDU 5536 Chip Factory Trie
    HDU 5510 Bazinga KMP
    HDU 4821 String 字符串哈希
    HDU 4814 Golden Radio Base 模拟
    LA 6538 Dinner Coming Soon DP
    HDU 4781 Assignment For Princess 构造
    LA 7056 Colorful Toy Polya定理
    LA 6540 Fibonacci Tree
  • 原文地址:https://www.cnblogs.com/chucklu/p/10337799.html
Copyright © 2011-2022 走看看