Megosztás a következőn keresztül:


HttpContentHeaderCollection.ContentType Property

Definition

Gets or sets the HttpMediaTypeHeaderValue object that represent the value of an HTTP Content-Type header on the HTTP content.

public:
 property HttpMediaTypeHeaderValue ^ ContentType { HttpMediaTypeHeaderValue ^ get(); void set(HttpMediaTypeHeaderValue ^ value); };
HttpMediaTypeHeaderValue ContentType();

void ContentType(HttpMediaTypeHeaderValue value);
public HttpMediaTypeHeaderValue ContentType { get; set; }
var httpMediaTypeHeaderValue = httpContentHeaderCollection.contentType;
httpContentHeaderCollection.contentType = httpMediaTypeHeaderValue;
Public Property ContentType As HttpMediaTypeHeaderValue

Property Value

The object that represent the value of an HTTP Content-Type header on the HTTP content. A null value means that the header is absent.

Remarks

The ContentType property represents the Content-Type header value on HTTP content. The Content-Type header is the MIME type of the content.

The following sample code shows a method to get or set the Content-Type header value on HTTP content using the ContentType property on the HttpContentHeaderCollection object.

// Content-Type header
// HttpMediaTypeHeaderValue (MediaType, Charset are strings, Parameters is an IList<HttpNameValueHeaderValue>)
//
void DemoContentType(IHttpContent content) {
    var h = content.Headers;
    h.ContentType = new HttpMediaTypeHeaderValue("myMediaType");

    var header = h.ContentType;
    uiLog.Text += "\nCONTENT TYPE HEADER\n";

    // Parameters is an IList<HttpNameValueHeaderValue> of Name/Value strings
    var parameterString = "";
    foreach (var parameter in header.Parameters) {
            parameterString += string.Format("[{0}={1}] ", parameter.Name, parameter.Value);
    }
    if (parameterString == "") {
            parameterString = "(no parameters)";
    }

    uiLog.Text += string.Format("Content-Type: MediaType: {0} CharSet: {1} Parameters: {2} ToString: {3}\n", header.MediaType, header.CharSet, parameterString, header.ToString());
}

Applies to

See also