在BeforeSendRequest中跳过标题验证

时间:2018-10-19 12:26:41

标签: c# web-services wcf .net-core http-headers

根据this主题,我正在使用此代码块

    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);
    }

但是不幸的是,因为我将代码从.net framwork 4.7移到.net core 2.1项目,所以我得到了以下错误代码:

  

无法复制带有值的HTTP标头“授权”   'qqqqqqqqq ='到   'System.Net.Http.Headers.HttpRequestHeaders'。\ r \ n值的格式   'qqqqqqqqq ='无效。

在旧项目中,一切正常 是否可以跳过Authorization标头验证? 谢谢

1 个答案:

答案 0 :(得分:0)

.net核心验证授权标头格式。 根据{{​​3}} 授权标头应采用以下格式:
items: item.map((value) { return new DropdownMenuItem( value: value['id'].toString(), child: new Text(value['name'])), }).toList()

如果您的授权标头不包含 type credentials 之间的空格或包含多个空格,则会出现此错误

可以正常工作:

Authorization: <type> <credentials>