Class HttpParametersParser
Namespace: System.Net
Assembly: System.Net.Http.Headers.dll
Provides functionality for parsing HTTP parameter strings.
Constructors
public HttpParametersParser()
Initializes a new instance of the HttpParametersParser class.
Methods
public static IDictionary<string, string> Parse(string input)
Parses a string containing HTTP parameters and returns them as a dictionary.
Parameters
| Name | Type | Description |
|---|---|---|
input |
string |
The string to parse. |
Returns
An IDictionary<string, string> containing the parsed parameters.
Example
using System;
using System.Collections.Generic;
using System.Net.Http.Headers;
public class Example
{
public static void Main(string[] args)
{
string headerValue = "charset=utf-8, boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW";
try
{
IDictionary<string, string> parameters = HttpParametersParser.Parse(headerValue);
foreach (var kvp in parameters)
{
Console.WriteLine($"Key: {kvp.Key}, Value: {kvp.Value}");
}
}
catch (FormatException ex)
{
Console.WriteLine($"Error parsing header: {ex.Message}");
}
}
}
Remarks
The HttpParametersParser class is useful for handling HTTP headers that contain lists of parameters, such as the Content-Type header.
It adheres to RFC 7230 and related specifications for parsing parameter formats.