Closed KamenRiderKuuga closed 3 years ago
@GadHao Looks like you have some stray commas in your code :smile:
- headers.TryGetValue("two,", out var two);
+ headers.TryGetValue("two", out var two);
Embarrassed, I even spent a morning on it
Describe the bug
When I want to get the header value from http request, I found something different from what I expected
To Reproduce
ASP.NET Core Web API
project.Request.Headers
byTryGetValue()
Go with the sample project
curl -i -H "Accept: application/json" -H "one: 111" -H "two: 222" -H "three: 333" http://localhost:5000/weatherforecast
Exceptions (if any)
Can't get header value by
headers.TryGetValue(key , out var value)
, but can get it fromheader[key]
If you go with the sample project, you will see:
Further technical details
.NET version: Reproduced in .NET Core 3.1 and .NET 5.0