当前位置: 首页>>代码示例>>C#>>正文


C# WebRequest.RepsondHeader方法代码示例

本文整理汇总了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();
        }
开发者ID:VanixxGraphix,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:14,代码来源:Authenticate.cs

示例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;
        }
开发者ID:VanixxGraphix,项目名称:Terraria-s-Dedicated-Server-Mod,代码行数:56,代码来源:HttpDigestAuth.cs


注:本文中的WebRequest.RepsondHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。