I'm trying to perform a web request from the client (NET Core 3.1) to a server. But I'm getting an error when passing custom information in headers. Please, I would like to know how to pass the information in the header. Thanks.
My code:
var request = (HttpWebRequest)WebRequest.Create("https://localhost:44351/mycontroller");
var postData = "n=42&s=25";
var data = Encoding.ASCII.GetBytes(postData);
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = data.Length;
request.Headers["X‐test"] = "884436999";
The exception:

Let's take a little tour at the related source code. In System.txt there is a row:
That means we should look for this
net_WebHeaderInvalidHeaderCharskey in the source code of WebHeaderCollection:This means that the error is thrown if the provided
namecontains some invalid characters.The
InvalidParamCharsare defined inside theInternalclass like this:So, all you have to do is to make sure that the request header name does not contain any of the not allowed characters.