GenericHeaderValue

System.Net.Http.Headers

Represents a generic HTTP header value that can be parsed from a string.

Inheritance

Constructors

Properties

Methods

Remarks

The GenericHeaderValue class is a simple way to represent HTTP header values that do not have a more specific type defined in the .NET framework. It allows you to store and retrieve header values as plain strings.

This class is useful when dealing with custom headers or headers that have a format not directly supported by built-in types.

Example


using System;
using System.Net.Http.Headers;

public class Example
{
    public static void Main(string[] args)
    {
        // Create a GenericHeaderValue for a custom header
        GenericHeaderValue customHeader = new GenericHeaderValue("MyCustomValue");

        Console.WriteLine($"Header Value: {customHeader.Value}");
        Console.WriteLine($"Header String: {customHeader.ToString()}");

        // Example with a standard but less common header format
        GenericHeaderValue acceptRangesHeader = new GenericHeaderValue("bytes");
        Console.WriteLine($"Accept-Ranges: {acceptRangesHeader.Value}");
    }
}
            
.NET 4.5, .NET Core 1.0, .NET Standard 1.3