HttpResponseMessage response = new HttpResponseMessage(); response.Content = new StringContent("Hello world!"); response.Content.Headers.ContentType = new MediaTypeHeaderValue("text/plain");
HttpRequestMessage request = new HttpRequestMessage(); MediaTypeHeaderValue contentType = request.Content.Headers.ContentType;In this example, the content type of the HTTP request message is retrieved and stored in a variable called contentType. Package/Library: The ContentType class is part of the System.Net.Http.Headers namespace in the .NET Framework. It is included in the System.Net.Http package.