我们在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
}
有人可以建议我为什么我无法通过"授权"?