本文整理汇总了C#中WebRequest.RepsondHeader方法的典型用法代码示例。如果您正苦于以下问题:C# WebRequest.RepsondHeader方法的具体用法?C# WebRequest.RepsondHeader怎么用?C# WebRequest.RepsondHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类WebRequest
的用法示例。
在下文中一共展示了WebRequest.RepsondHeader方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProcessRequest
//TODO simple JSON writer
//struct Info
//{
// public string Provider { get; set; }
//}
public override void ProcessRequest(WebRequest request)
{
request.StatusCode = 200;
request.RepsondHeader(200, "OK", "application/octet-stream", 1);
request.Send(request.AuthenticatedAs != null);
request.End();
}
示例2: Authenticate
public string Authenticate(WebRequest request)
{
//username=MD5(HA1:nonce:HA2),realm
//Initially I was thinking we could simply use the hash as the KEY, and the username as the VALUE.
//But i rather have the user being asked for and then compare, rather that matching on ALL user hashs and using whatever username was found.
//The odds are small, but I have no justification for it as of yet so I am sticking with the username key.
if (request.Headers.ContainsKey("Auth"))
{
var auth = request.Headers["Auth"];
var split = auth.Split('=');
if (split.Length == 2)
{
var username = split[0];
split = split[1].Split(',');
if (split.Length == 2 && split[0].Length == 32)
{
var hash = split[0];
var realm = split[1];
if (realm == WebServer.ProviderName)
{
var key = request.IPAddress + '+' + username;
var ha1 = _database.Find(username);
if (_lastNonceLookup.ContainsKey(key) && ha1 != null)
{
var servernonce = _lastNonceLookup[key];
var ha2 = ComputeHash("auth:" + request.Path);
var serverHash = ComputeHash(ha1 + ':' + servernonce + ':' + ha2);
if (serverHash == hash)
{
//Push out the new nonce
var nextnonce = Guid.NewGuid().ToString();
_lastNonceLookup[key] = nextnonce;
request.ResponseHeaders.Add("next-nonce", nextnonce);
return username;
}
}
else
{
//No user exists, so give the request a new nonce and let them revalidate
var nextnonce = Guid.NewGuid().ToString();
_lastNonceLookup.Add(key, nextnonce);
request.ResponseHeaders.Add("next-nonce", nextnonce);
request.RepsondHeader(403, "OK", "text/hml", 0);
request.End();
}
}
}
}
}
return null;
}