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


C# HttpListenerContext类代码示例

本文整理汇总了C#中HttpListenerContext的典型用法代码示例。如果您正苦于以下问题:C# HttpListenerContext类的具体用法?C# HttpListenerContext怎么用?C# HttpListenerContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


HttpListenerContext类属于命名空间,在下文中一共展示了HttpListenerContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetPeople

        public bool GetPeople(WebServer server, HttpListenerContext context)
        {
            try
            {
                // read the last segment
                var lastSegment = context.Request.Url.Segments.Last();

                // if it ends with a / means we need to list people
                if (lastSegment.EndsWith("/"))
                    return context.JsonResponse(PeopleRepository.Database);

                // otherwise, we need to parse the key and respond with the entity accordingly
                int key;

                if (int.TryParse(lastSegment, out key) && PeopleRepository.Database.Any(p => p.Key == key))
                {
                    return context.JsonResponse(PeopleRepository.Database.FirstOrDefault(p => p.Key == key));
                }

                throw new KeyNotFoundException("Key Not Found: " + lastSegment);
            }
            catch (Exception ex)
            {
                context.Response.StatusCode = (int)System.Net.HttpStatusCode.InternalServerError;
                return context.JsonResponse(ex);
            }
        }
开发者ID:unosquare,项目名称:embedio,代码行数:27,代码来源:TestController.cs

示例2: ResponseHandler

	static void ResponseHandler (HttpListenerContext httpContext)
	{
		byte [] buffer = Encoding.ASCII.GetBytes ("hello world");
		httpContext.Response.StatusCode = 200;
		httpContext.Response.OutputStream.Write (buffer, 0, buffer.Length);
		httpContext.Response.Close ();
	}
开发者ID:mono,项目名称:gert,代码行数:7,代码来源:server.cs

示例3: ProcessRequest

    public IEnumerator ProcessRequest(HttpListenerContext context, System.Action<bool> isMatch)
    {
        string url = context.Request.RawUrl;

        //Debug.Log (url);

        bool match = false;
        foreach(Regex regex in regexList)
        {
            if (regex.Match(url).Success)
            {
                match = true;
                break;
            }
        }

        if (!match)
        {
            isMatch(false);
            yield break;
        }

        IEnumerator e = OnRequest(context);
        do
        {
            yield return null;
        }
        while (e.MoveNext());

        isMatch(true);
    }
开发者ID:FomTarro,项目名称:CrimeTimeUNET,代码行数:31,代码来源:WebServerRule.cs

示例4: OnRequest

    protected override IEnumerator OnRequest(HttpListenerContext context)
    {
        Debug.Log ("Some Random String");
        HttpListenerResponse response = context.Response;
        Stream stream = response.OutputStream;

        response.ContentType = "application/octet-stream";

        byte[] data = unityWebPackage.bytes;

        int i = 0;
        int count = data.Length;

        while(i < count)
        {
            if (i != 0)
                yield return null;

            int writeLength = Math.Min((int)writeStaggerCount, count - i);

            stream.Write(data, i, writeLength);

            i += writeLength;
        }
    }
开发者ID:bonbombs,项目名称:CrimeTimeUNET,代码行数:25,代码来源:UnityWebPlayerRule.cs

示例5: OnRequest

    protected override IEnumerator OnRequest(HttpListenerContext context)
    {
        Debug.Log("Hello:" + context.Request.UserHostAddress);

        string html = htmlPage.text;

        foreach(HtmlKeyValue pair in substitutions)
        {
            html = html.Replace(string.Format("${0}$", pair.Key), pair.Value);
        }

        html = ModifyHtml(html);

        byte[] data = Encoding.ASCII.GetBytes(html);

        yield return null;

        HttpListenerResponse response = context.Response;

        response.ContentType = "text/html";

        Stream responseStream = response.OutputStream;

        int count = data.Length;
        int i = 0;
        while(i < count)
        {
            if (i != 0)
                yield return null;

            int writeLength = Math.Min((int)writeStaggerCount, count - i);
            responseStream.Write(data, i, writeLength);
            i += writeLength;
        }
    }
开发者ID:FomTarro,项目名称:CrimeTimeUNET,代码行数:35,代码来源:HtmlRule.cs

示例6: HttpListenerWebSocketContext

   internal HttpListenerWebSocketContext(
 HttpListenerContext context, Logger logger)
   {
       _context = context;
         _stream = WsStream.CreateServerStream (context);
         _websocket = new WebSocket (this, logger ?? new Logger ());
   }
开发者ID:uken,项目名称:websocket-sharp,代码行数:7,代码来源:HttpListenerWebSocketContext.cs

示例7: Handle

    public void Handle(HttpListenerContext context)
    {
        HttpListenerResponse response = context.Response;

        // Get device data
        string id = context.Request.QueryString["id"];
        Device device = _deviceManager.FindDeviceByID(id);

        // Create response
        string message = "{\"Version\":\"2.0.1\", \"Auth\": \"";
        response.StatusCode = (int)HttpStatusCode.OK;

        if (device != null || !_deviceManager.AuthenticationEnabled) {
            message += "OK\"}";
        } else {
            message += "DENIED\"}";
        }

        // Fill in response body
        byte[] messageBytes = Encoding.Default.GetBytes(message);
        response.OutputStream.Write(messageBytes, 0, messageBytes.Length);
        response.ContentType = "application/json";

        // Send the HTTP response to the client
        response.Close();
    }
开发者ID:sakisds,项目名称:Icy-Monitor,代码行数:26,代码来源:AuthHttpRequestHandler.cs

示例8: GetPeople

        public bool GetPeople(WebServer server, HttpListenerContext context)
        {
            try
            {
                // read the last segment
                var lastSegment = context.Request.Url.Segments.Last();

                // if it ends with a / means we need to list people
                if (lastSegment.EndsWith("/"))
                    return context.JsonResponse(_dbContext.People.SelectAll());

                // if it ends with "first" means we need to show first record of people
                if (lastSegment.EndsWith("first"))
                    return context.JsonResponse(_dbContext.People.SelectAll().First());

                // otherwise, we need to parse the key and respond with the entity accordingly
                int key = 0;
                if (int.TryParse(lastSegment, out key))
                {
                    var single = _dbContext.People.Single(key);

                    if (single != null)
                        return context.JsonResponse(single);
                }

                throw new KeyNotFoundException("Key Not Found: " + lastSegment);
            }
            catch (Exception ex)
            {
                // here the error handler will respond with a generic 500 HTTP code a JSON-encoded object
                // with error info. You will need to handle HTTP status codes correctly depending on the situation.
                // For example, for keys that are not found, ou will need to respond with a 404 status code.
                return HandleError(context, ex, (int)System.Net.HttpStatusCode.InternalServerError);
            }
        }
开发者ID:unosquare,项目名称:embedio,代码行数:35,代码来源:PeopleController.cs

示例9: HttpListenerHost

            public HttpListenerHost(HttpListenerContext context, string serviceUri)
            {
                this.httpListenerContext = context;

                // retrieve request information from HttpListenerContext
                HttpListenerRequest contextRequest = context.Request;
                this.AbsoluteRequestUri = new Uri(contextRequest.Url.AbsoluteUri);
                this.AbsoluteServiceUri = new Uri(serviceUri);
                this.RequestPathInfo = this.AbsoluteRequestUri.MakeRelativeUri(this.AbsoluteServiceUri).ToString();

                // retrieve request headers
                this.RequestAccept = contextRequest.Headers[HttpAccept];
                this.RequestAcceptCharSet = contextRequest.Headers[HttpAcceptCharset];
                this.RequestIfMatch = contextRequest.Headers[HttpIfMatch];
                this.RequestIfNoneMatch = contextRequest.Headers[HttpIfNoneMatch];
                this.RequestMaxVersion = contextRequest.Headers[HttpMaxDataServiceVersion];
                this.RequestVersion = contextRequest.Headers[HttpDataServiceVersion];
                this.RequestContentType = contextRequest.ContentType;

                this.RequestHeaders = new WebHeaderCollection();
                foreach (string header in contextRequest.Headers.AllKeys)
                    this.RequestHeaders.Add(header, contextRequest.Headers.Get(header));

                this.QueryStringValues = new Dictionary<string, string>();
                string queryString = this.AbsoluteRequestUri.Query;
                var parsedValues = HttpUtility.ParseQueryString(queryString);
                foreach (string option in parsedValues.AllKeys)
                    this.QueryStringValues.Add(option, parsedValues.Get(option));

                processExceptionCalled = false;
            }
开发者ID:larsenjo,项目名称:odata.net,代码行数:31,代码来源:IDataServiceHostRunner.cs

示例10: HandleReqest

        /// <summary>
        /// Request handler function. Overriden from RequestHandler class
        /// </summary>
        /// <param name="context">Request context</param>
        public override void HandleReqest(HttpListenerContext context)
        {
            _content.Append(TemplateText);

            if (context.Request.HttpMethod == "GET")
            {
                if (GetHandler != null)
                {
                    GetHandler(this, new HTTPEventArgs(EmbeddedHttpServer.GetFileName(context.Request.RawUrl), context.Request.QueryString));
                }
            }

            if (TemplateTags != null)
            {
                foreach (var keyvaluepair in TemplateTags)
                {
                    var toreplace = "{{" + keyvaluepair.Key + "}}";
                    _content.Replace(toreplace, keyvaluepair.Value.ToString());
                }
            }

            MarkdownSharp.Markdown md = new MarkdownSharp.Markdown();

            var output = Encoding.UTF8.GetBytes(BaseHTMLTemplate.Replace("{{md}}", md.Transform(_content.ToString())));
            context.Response.ContentType = "text/html";
            context.Response.ContentLength64 = output.Length;
            context.Response.OutputStream.Write(output, 0, output.Length);
        }
开发者ID:webmaster442,项目名称:EmbeddedHttpServer,代码行数:32,代码来源:MarkDownTemplateHandler.cs

示例11: HttpListenerRequest

		internal HttpListenerRequest (HttpListenerContext context)
		{
			this.context = context;
			headers = new WebHeaderCollection ();
			input_stream = Stream.Null;
			version = HttpVersion.Version10;
		}
开发者ID:calumjiao,项目名称:Mono-Class-Libraries,代码行数:7,代码来源:HttpListenerRequest.cs

示例12: HttpListenerRequest

 internal HttpListenerRequest(HttpListenerContext context)
 {
     _context = context;
     _contentLength = -1;
     _headers = new WebHeaderCollection ();
     _identifier = Guid.NewGuid ();
     _version = HttpVersion.Version10;
 }
开发者ID:richardfeng,项目名称:UnitySocketIO-WebSocketSharp,代码行数:8,代码来源:HttpListenerRequest.cs

示例13: ChunkedInputStream

		public ChunkedInputStream (
			HttpListenerContext context, Stream stream, byte [] buffer, int offset, int length)
			: base (stream, buffer, offset, length)
		{
			this.context = context;
			WebHeaderCollection coll = (WebHeaderCollection) context.Request.Headers;
			decoder = new ChunkStream (coll);
		}
开发者ID:fengxianqi,项目名称:Youbang,代码行数:8,代码来源:ChunkedInputStream.cs

示例14: HttpListenerRequest

        internal HttpListenerRequest(HttpListenerContext context)
        {
            this.context = context;

            headers = new WebHeaderCollection();

            version = HttpVersion.Version10;
        }
开发者ID:jamesaxl,项目名称:reactor,代码行数:8,代码来源:HttpListenerRequest.cs

示例15: InvokeHandler

 private void InvokeHandler(IHttpRequestHandler handler, HttpListenerContext context)
 {
     if (handler == null)
         return;
     Console.WriteLine("Request being handled");
     HandleHttpRequestCommand command = new HandleHttpRequestCommand(handler, context);
     Thread commandThread = new Thread(command.Execute);
     commandThread.Start();
 }
开发者ID:jordanbang,项目名称:MusicDiff-Windows,代码行数:9,代码来源:HttpResourceLocator.cs


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