根据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);
}
但不幸是,自从我将代码从. netframwork4.7移到. netcore2.1项目后,我得到了以下错误代码:
未能将值为“qqqqqqqqq=”的HTTP标头“Authorization”复制到“System.Net.Http.Headers. HttpRequestHeaders”。\r\n值“qqqqqqqqq=”的格式无效。
在旧项目中,一切正常,是否可以跳过授权标题验证?谢谢
1条答案
按热度按时间pw9qyyiw1#
.net核心验证受权信头格式。根据https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Authorization,受权信头的格式应为:
Authorization: <type> <credentials>
如果授权头在
type
和credentials
之间不包含空格或包含多个空格,则会出现此错误这将很好地工作: