0

According to this topic I am using this block of code

    public object BeforeSendRequest(ref System.ServiceModel.Channels.Message request,  System.ServiceModel.IClientChannel channel)
{
    HttpRequestMessageProperty httpRequestMessage;
    object httpRequestMessageObject;
    if (request.Properties.TryGetValue(HttpRequestMessageProperty.Name, out httpRequestMessageObject))
    {
        httpRequestMessage = httpRequestMessageObject as HttpRequestMessageProperty;
        if (string.IsNullOrEmpty(httpRequestMessage.Headers[USER_AGENT_HTTP_HEADER]))
        {
            httpRequestMessage.Headers[USER_AGENT_HTTP_HEADER] = this.m_userAgent;
        }
    }
    else
    {
        httpRequestMessage = new HttpRequestMessageProperty();
        requestMessageProperty.Headers.Add("Authorization",  token);
        request.Properties.Add(HttpRequestMessageProperty.Name, httpRequestMessage);
    }

but unfortunately since I move code from .net framwork 4.7 to .net core 2.1 project I am getting this error code:

Failed to copy the HTTP header 'Authorization' with value 'qqqqqqqqq=' to 'System.Net.Http.Headers.HttpRequestHeaders'.\r\nThe format of value 'qqqqqqqqq=' is invalid.

In old project everything worked fine Is possible to skip Authorization header validation? Thank you

1 Answers1

0

.net core validates Authorization header format. According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization the authorization header should be in format:
Authorization: <type> <credentials>

You will get this error if your authorization header doesn't contain space between type and credentials or contains multiple spaces

This will work fine:

requestMessageProperty.Headers.Add("Authorization", $"my-custom-auth-type {token}");