You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Webhook请求头携带用户名密码验证真实性时参数读取失败如何解决

问题根因与解决方法

1. 现有代码存在的明显错误

你在判断X-DocuSign-UserName头存在的分支中,错误读取了X-DocuSign-Password头的内容赋值给username1,这会导致即便是自定义头存在,你也拿不到正确的用户名。

2. DocuSign Webhook身份验证的正确参数位置

DocuSign Connect的基础身份验证默认走标准HTTP Basic认证规范,不会单独传递X-DocuSign-UserName、username这类自定义头:

  • 身份凭证会存储在名为Authorization的请求头中
  • 头值格式为Basic 【Base64编码的用户名:密码字符串】

3. 正确的读取代码示例

System.Net.Http.Headers.HttpRequestHeaders headers = Request.Headers;
string username = string.Empty;
string password = string.Empty;

// 优先读取标准Basic认证头
if (headers.Contains("Authorization"))
{
    string authHeader = headers.GetValues("Authorization").First();
    if (authHeader.StartsWith("Basic ", StringComparison.OrdinalIgnoreCase))
    {
        // 提取Base64编码部分并解码
        string encodedCredentials = authHeader.Substring("Basic ".Length).Trim();
        byte[] credentialBytes = Convert.FromBase64String(encodedCredentials);
        string credentials = System.Text.Encoding.UTF8.GetString(credentialBytes);
        // 分割得到用户名和密码 分隔符为英文冒号
        var credentialParts = credentials.Split(new[] { ':' }, 2);
        if (credentialParts.Length == 2)
        {
            username = credentialParts[0];
            password = credentialParts[1];
        }
    }
}
// 如果你确实配置了自定义头传递凭证,再补充以下逻辑
else if (headers.Contains("X-DocuSign-UserName") && headers.Contains("X-DocuSign-Password"))
{
    username = headers.GetValues("X-DocuSign-UserName").First();
    password = headers.GetValues("X-DocuSign-Password").First();
}

4. 可选排查项

如果还是拿不到值,可以先打印所有请求头的键值对,确认实际传递的头名:

foreach (var header in headers)
{
    Console.WriteLine($"{header.Key}: {string.Join(",", header.Value)}");
}

内容的提问来源于stack exchange,提问作者Shyam Vashista

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.27 18:24:02