Example in C# client
var c = new HttpClient();
c.DefaultRequestHeaders.Add("X-MyHeader", "123,abc"); // What delimiter? , ; & are not working.
In the Server
var Vals = Request.Headers["X-MyHeader"];
Since the Headers returns a StringValues object, may I know what delimiter shall I use at the client side, so that the string can be automatically parsed as '123' and 'abc' separately?
HttpHeaders collection handle the separators.The Add() method can be called multiple times with a single value or with a list of values.
The HttpHeaders collection doesn't behave the same as a Dictionary<string, string>. One key can contain multiple values. They are send separated by comma's. See:
https://learn.microsoft.com/en-us/dotnet/api/system.net.http.headers.httpheaders.add?view=net-7.0
The list can be added in one call with the Add(String, IEnumerable<String>) overload, if you have the strings in a enumerable collection of some sort.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With