"授权"从hmac客户端传输到服务器时,HttpWebRequest中传递的标头变为null

时间:2016-09-23 06:16:32

标签: c# authorization httpwebrequest hmac

我们在HttpWebRequest

中传递了三个标题
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/api/xxx?xid=5");

 private HttpWebRequest SetHeaders(HttpWebRequest request)
        {
            string timestamp = DateTime.Now.Millisecond.ToString();
            request.Headers.Add("ts", timestamp);
            request.Headers.Add("un", cwUserId);

            string representation = String.Join("\n", request.Method, timestamp, cwUserId, request.RequestUri.AbsoluteUri.ToLower());

            var encryptedKey = Sha1Hash(cwSecretKey);
            string signature = Signature(encryptedKey, representation);

            request.Headers.Add("Authorization", signature);
            return request;
        }

当此请求到达我们的api代码时: 我们尝试阅读标题,我们能够阅读" ts"," un"。但是"授权"是空字符串。

在我的api方面, 我有HttpActionContext actionContext。 当我这样做时:

var headers = _actionContext.Request.Headers;

标题包含:

{Accept-Encoding: gzip
ts: 553
un: cwuser
X-REWRITE-URL: /api/usedcarleads/?dealerid=5
}

如果我将标题名称更改为" Authorizatio",我可以看到标题值:

{Accept-Encoding: gzip
ts: 858
un: cwuser
Authorizatio: ENsAgXIHql/LJ09D1752SQCIq8Uf8u3xAxLbqr45JG4=
X-REWRITE-URL: /api/usedcarleads/?dealerid=5
}

有人可以建议我为什么我无法通过"授权"?

0 个答案:

没有答案