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


C# Net.HttpListenerResponse类代码示例

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


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

示例1: WriteResponseDto

 private static void WriteResponseDto(HttpListenerResponse response, ISerializer serializer, MyDummyResponse responseDto)
 {
     using (var writer = new StreamWriter(response.OutputStream, Encoding.UTF8))
     {
         serializer.Serialize(writer, responseDto);
     }
 }
开发者ID:andreasetti,项目名称:TestFirst.Net,代码行数:7,代码来源:SerializerRequestProcessor.cs

示例2: HttpListenerResponseAdapter

        /// <summary>
        /// Initializes a new instance of the <see cref="HttpListenerResponseAdapter" /> class.
        /// </summary>
        /// <param name="Response">The <see cref="HttpListenerResponse" /> to adapt for WebDAV#.</param>
        /// <exception cref="System.ArgumentNullException">Response</exception>
        /// <exception cref="ArgumentNullException"><paramref name="Response" /> is <c>null</c>.</exception>
        public HttpListenerResponseAdapter(HttpListenerResponse Response)
        {
        if (Response == null)
            throw new ArgumentNullException("Response");

        _response = Response;
        }
开发者ID:SOACAt,项目名称:WebDAVSharp.Server,代码行数:13,代码来源:HttpListenerResponseAdapter.cs

示例3: HttpListenerResponseAdapter

        /// <summary>
        ///     Initializes a new instance of the <see cref="HttpListenerResponseAdapter" /> class.
        /// </summary>
        /// <param name="response">The <see cref="HttpListenerResponse" /> to adapt for WebDAV#.</param>
        /// <exception cref="System.ArgumentNullException">Response</exception>
        /// <exception cref="ArgumentNullException"><paramref name="response" /> is <c>null</c>.</exception>
        public HttpListenerResponseAdapter(HttpListenerResponse response)
        {
            if (response == null)
                throw new ArgumentNullException(nameof(response));

            _response = response;
        }
开发者ID:Winterleaf,项目名称:WebDAVSharp.Server,代码行数:13,代码来源:HttpListenerResponseAdapter.cs

示例4: GetFileHandler

        static void GetFileHandler(HttpListenerRequest request, HttpListenerResponse response)
        {
            var query = request.QueryString;
            string targetLocation = query["target"];
            Log ("GetFile: " + targetLocation + "...");

            if(File.Exists(targetLocation))
            {
                try
                {
                    using(var inStream = File.OpenRead(targetLocation))
                    {
                        response.StatusCode = 200;
                        response.ContentType = "application/octet-stream";
                        CopyStream(inStream, response.OutputStream);
                    }
                }
                catch(Exception e)
                {
                    Log (e.Message);
                    response.StatusCode = 501;
                }
            }
            else
            {
                response.StatusCode = 501;
                Log ("File doesn't exist");
            }
        }
开发者ID:bizarrefish,项目名称:TestVisor,代码行数:29,代码来源:VMAgentServer.cs

示例5: Handle

 public override object Handle(Project project, object body, HttpListenerResponse response)
 {
     return project
         .GetVersions()
         .OrderByDescending(v => v)
         .FirstOrDefault();
 }
开发者ID:Troposphir,项目名称:AtmoLauncher,代码行数:7,代码来源:GetVersion.cs

示例6: ResponseWrite

 public static void ResponseWrite(HttpListenerResponse response, string content)
 {
     using (StreamWriter sw = new StreamWriter(response.OutputStream))
     {
         sw.Write(content);
     }
 }
开发者ID:imzjy,项目名称:MiniHttpServer,代码行数:7,代码来源:MiniUtility.cs

示例7: Response

        public Response(HttpListenerResponse response, App app)
        {
            _response = response;
            _writer = new StreamWriter(new BufferedStream(response.OutputStream));

            App = app;
        }
开发者ID:dfcook,项目名称:Express.NET,代码行数:7,代码来源:Response.cs

示例8: RequestHandler

        void RequestHandler(HttpListenerRequest req, HttpListenerResponse res)
        {
            Console.WriteLine("[RequestHandler: req.url=" + req.Url.ToString());

            if (req.Url.AbsolutePath == "/cmd/record/start") {
                Record.Start(req, res);
            }
            else if (req.Url.AbsolutePath == "/cmd/record/stop") {
                Record.Stop(req, res);
            }
            else if (req.Url.AbsolutePath == "/cmd/livingcast/start") {
                LivingCast.Start(req, res);
            }
            else if (req.Url.AbsolutePath == "/cmd/livingcast/stop") {
                LivingCast.Stop(req, res);
            }
            else {
                res.StatusCode = 404;
                res.ContentType = "text/plain";

                try
                {
                    StreamWriter sw = new StreamWriter(res.OutputStream);
                    sw.WriteLine("NOT supported command: " + req.Url.AbsolutePath);
                    sw.Close();
                }
                catch { }
            }
        }
开发者ID:FihlaTV,项目名称:conference,代码行数:29,代码来源:Server.cs

示例9: Process

 public override void Process(HttpListenerRequest request, HttpListenerResponse response)
 {
     using (var stream = typeof(StaticHandler).Assembly.GetManifestResourceStream("SongRequest.Static.favicon.ico"))
     {
         stream.CopyTo(response.OutputStream);
     }
 }
开发者ID:spdr870,项目名称:SongRequest,代码行数:7,代码来源:FaviconHandler.cs

示例10: SendHttpResponse

 private void SendHttpResponse(TcpClient client, Stream stream, HttpListenerResponse response, byte[] body)
 {
     // Status line
     var statusLine = $"HTTP/1.1 {response.StatusCode} {response.StatusDescription}\r\n";
     var statusBytes = Encoding.ASCII.GetBytes(statusLine);
     stream.Write(statusBytes, 0, statusBytes.Length);
     // Headers
     foreach (var key in response.Headers.AllKeys)
     {
         var value = response.Headers[key];
         var line = $"{key}: {value}\r\n";
         var lineBytes = Encoding.ASCII.GetBytes(line);
         stream.Write(lineBytes, 0, lineBytes.Length);
     }
     // Content-Type header
     var contentType = Encoding.ASCII.GetBytes($"Content-Type: {response.ContentType}\r\n");
     stream.Write(contentType, 0, contentType.Length);
     // Content-Length header
     var contentLength = Encoding.ASCII.GetBytes($"Content-Length: {body.Length}\r\n");
     stream.Write(contentLength, 0, contentLength.Length);
     // "Connection: close", to tell the client we can't handle persistent TCP connections
     var connection = Encoding.ASCII.GetBytes("Connection: close\r\n");
     stream.Write(connection, 0, connection.Length);
     // Blank line to indicate end of headers
     stream.Write(new[] { (byte)'\r', (byte)'\n' }, 0, 2);
     // Body
     stream.Write(body, 0, body.Length);
     stream.Flush();
     // Graceful socket shutdown
     client.Client.Shutdown(SocketShutdown.Both);
     client.Dispose();
 }
开发者ID:LindaLawton,项目名称:google-api-dotnet-client,代码行数:32,代码来源:HttpListener.cs

示例11: ResponseException

        private void ResponseException(
            string method, string path, Exception ex, ISession session, HttpListenerResponse response)
        {
            string body = null;
            var httpStatus = HttpStatusCode.InternalServerError;
            string contentType = "application/json";

            if (ex is FailedCommandException)
            {
                var message = new Dictionary<string, object>
                {
                    { "sessionId", (session != null ? session.ID : null) },
                    { "status", ((FailedCommandException)ex).Code },
                    { "value", new Dictionary<string, object>
                        {
                            { "message", ex.Message } // TODO stack trace
                        }
                    }
                };

                body = JsonConvert.SerializeObject(message);
            }
            else
            {
                httpStatus = HttpStatusCode.BadRequest;
                contentType = "text/plain";
                body = ex.ToString();
            }

            this.WriteResponse(response, httpStatus, contentType, body);
        }
开发者ID:shaunstanislaus,项目名称:winappdriver,代码行数:31,代码来源:Server.cs

示例12: request_handler

 private void request_handler(HttpListenerResponse handler_response, HttpListenerRequest handler_request)
 {
     string document = handler_request.RawUrl;
     string docpath = root_path + document;
     byte[] responsebyte;
     if (File.Exists(docpath))
     {
         handler_response.StatusCode = (int)HttpStatusCode.OK;
         handler_response.ContentType = "text/html";
         responsebyte = File.ReadAllBytes(docpath);
     }
     else
     {
         if (debug)
         {
             handler_response.StatusCode = (int)HttpStatusCode.NotFound;
             string responsestring = "Server running! ";
             responsestring += "document: " + document + " ";
             responsestring += "documentpath: " + docpath + " ";
             responsestring += "root_path " + root_path + " ";
             responsebyte = System.Text.Encoding.UTF8.GetBytes(responsestring);
         }
         else
         {
             handler_response.StatusCode = (int)HttpStatusCode.NotFound;
             handler_response.ContentType = "text/html";
             responsebyte = File.ReadAllBytes(root_path + "//error//error.html");
         }
     }
     handler_response.ContentLength64 = responsebyte.Length;
     System.IO.Stream output = handler_response.OutputStream;
     output.Write(responsebyte, 0, responsebyte.Length);
     output.Close();
 }
开发者ID:radtek,项目名称:winmon,代码行数:34,代码来源:Server.cs

示例13: Run

 /// <summary>
 /// Выполняет приложение
 /// Для запросов GET возвращает все записи.
 /// Для запросов POST создает и сохраняет новые записи.
 /// </summary>
 /// <param name="request">Request.</param>
 /// <param name="response">Response.</param>
 public override void Run(HttpListenerRequest request, HttpListenerResponse response)
 {
     if (request.HttpMethod == "POST")
     {
         if (request.HasEntityBody)
         {
             // читаем тело запроса
             string data = null;
             using (var reader = new StreamReader(request.InputStream))
             {
                 data = reader.ReadToEnd ();
             }
             if (!string.IsNullOrWhiteSpace(data))
             {
                 // формируем коллекцию параметров и их значений
                 Dictionary<string, string> requestParams = new Dictionary<string, string>();
                 string[] prms = data.Split('&');
                 for (int i = 0; i < prms.Length; i++)
                 {
                     string[] pair = prms[i].Split('=');
                     requestParams.Add(pair[0], Uri.UnescapeDataString(pair[1]).Replace('+',' '));
                 }
                 SaveEntry (GuestbookEntry.FromDictionary(requestParams));
             }
             response.Redirect(request.Url.ToString());
             return;
         }
     }
     DisplayGuestbook (response);
 }
开发者ID:nixxa,项目名称:HttpServer,代码行数:37,代码来源:GuestbookApplication.cs

示例14: HandleRequest

        /// <summary>
        /// handle left clicks from client
        /// </summary>
        /// <param name="response"></param>
        /// <param name="uri"></param>
        /// <returns></returns>
        public override byte[] HandleRequest(HttpListenerResponse response, string[] uri)
        {
            // must have 5 tokens
            if (uri.Length != 7)
            {
                response.StatusCode = 400;
                return BuildHTML("Error...");
            }

            int screen = GetRequestedScreenDevice(uri, screens);

            bool error = handleMouseDown(uri, screen);
            if (error)
            {
                // parameter error
                response.StatusCode = 400;
                return BuildHTML("Error...");
            }

            error = handleMouseUp(uri, screen);
            if (error)
            {
                // parameter error
                response.StatusCode = 400;
                return BuildHTML("Error...");
            }

            return BuildHTML("Updating...");
        }
开发者ID:badou119,项目名称:RemoteView,代码行数:35,代码来源:LeftClickPageHandler.cs

示例15: HandleRequest

 /// <summary>
 /// Get a copy of the requested device screen image from cache
 /// </summary>
 /// <param name="response"></param>
 /// <param name="uri"></param>
 /// <returns></returns>
 public override byte[] HandleRequest(HttpListenerResponse response, String[] uri)
 {
     int requested = GetRequestedScreenDevice(uri, screens);
     lastScreenRequested = requested;
     response.Headers.Set("Content-Type", "image/png");
     return caches[requested];
 }
开发者ID:badou119,项目名称:RemoteView,代码行数:13,代码来源:ScreenPageHandler.cs


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