Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

The header name format is invalid

$
0
0

<script type="text/javascript" src="//s3.amazonaws.com/js-cache/188f9ebcdf6890da18.js"></script>

Hi,

I am getting inconsistent behaviour when adding a custom header to my HttpRequestMessage. When I add the header using a variable, I get System.FormatException: 'The header name format is invalid. When I explicitly define the header string (hard code it) it works. I can confirm the value passed to the variable is exactly the same. Here is my method, which may aid in reproducing:

        private static void AddSecurityRequestHeaders(HttpRequestMessage httpRequestMessage, string securityHeader, string securityValue)
        {
            httpRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue(Constants.Http.JsonMediaType));
            httpRequestMessage.Headers.Add(securityHeader, securityValue);
            //httpRequestMessage.Headers.Add("BusinessSecKey", "SecurityKeyValue");
        }

If you uncomment and use the section of code using the hard-coded header and value, it works.

If this is by design, can someone please explain to me what is going on?


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>