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


C# HttpListenerResponse.Close方法代码示例

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


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

示例1: Process

		public void Process(HttpListenerRequest request, HttpListenerResponse response)
		{
			try
			{
				if (request.HttpMethod != "GET")
				{
					response.StatusCode = 405;
					response.StatusDescription = "Method Not Supported";
					response.Close();
					return;
				}

				string version = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion;
				string status = GetStatusDescription();
				string timestamp = DateTime.UtcNow.ToString("s", CultureInfo.InvariantCulture) + "Z";

				FormatJsonResponse(response, version, status, timestamp);
			}
			catch (HttpListenerException hlex)
			{
				Supervisor.LogException(hlex, TraceEventType.Error, request.RawUrl);

				response.StatusCode = 500;
				response.StatusDescription = "Error Occurred";
				response.Close();
			}
		}
开发者ID:Philo,项目名称:Revalee,代码行数:27,代码来源:StatusRequestHandler.cs

示例2: SendResponse

 public static void SendResponse(HttpListenerResponse response, byte[] buffer)
 {
     response.ContentLength64 = buffer.Length;
     response.OutputStream.Write(buffer, 0, buffer.Length);
     response.OutputStream.Close();
     response.Close();
 }
开发者ID:peec,项目名称:honorbuddy-ws,代码行数:7,代码来源:HttpServer.cs

示例3: SendResponse

        public static void SendResponse(HttpListenerResponse response, string str)
        {
            var result = Encoding.UTF8.GetBytes(str);

            response.ContentLength64 = result.Length;
            response.OutputStream.Write(result, 0, result.Count());
            response.Close();
        }
开发者ID:Wanderer19,项目名称:Tasks,代码行数:8,代码来源:Program.cs

示例4: SendResponse

 public static void SendResponse(HttpListenerResponse response, string content)
 {
     byte[] buffer = Encoding.UTF8.GetBytes(content);
     response.StatusCode = (int) HttpStatusCode.OK;
     response.StatusDescription = "OK";
     response.ContentType = "text/html; charset=UTF-8";
     response.ContentLength64 = buffer.Length;
     response.ContentEncoding = Encoding.UTF8;
     response.OutputStream.Write(buffer, 0, buffer.Length);
     response.OutputStream.Close();
     response.Close();
 }
开发者ID:habb0,项目名称:Bluedot,代码行数:12,代码来源:WebAdminManager.cs

示例5: authenticate

        public void authenticate(HttpListenerRequest req, HttpListenerResponse res, HTTPSession session)
        {
            // use the session object to store state between requests
            session["nonce"] = RandomString();
            session["state"] = RandomString();

            // TODO make authentication request

            // TODO insert the redirect URL
            string login_url = null;
            res.Redirect(login_url);
            res.Close();
        }
开发者ID:biancini,项目名称:openid_course,代码行数:13,代码来源:Client.cs

示例6: SendResponse

 public static void SendResponse(HttpListenerResponse response, string pluginName, string content)
 {
     CoreManager.ServerCore.GetStandardOut().PrintDebug("WebAdmin Response [" + pluginName + "]: " + content);
     byte[] buffer = Encoding.UTF8.GetBytes(content);
     response.StatusCode = (int) HttpStatusCode.OK;
     response.StatusDescription = "OK";
     response.ContentType = "text/html; charset=UTF-8";
     response.ContentLength64 = buffer.Length;
     response.ContentEncoding = Encoding.UTF8;
     response.AddHeader("plugin-name", pluginName);
     response.OutputStream.Write(buffer, 0, buffer.Length);
     response.OutputStream.Close();
     response.Close();
 }
开发者ID:habb0,项目名称:IHI,代码行数:14,代码来源:WebAdminManager.cs

示例7: SendResponse

        public void SendResponse(HttpListenerRequest request, HttpListenerResponse response)
        {
            var stream = new FileLoader(request.Url.AbsolutePath).LoadStream();

            response.ContentLength64 = stream.Length;
            response.SendChunked = false;
            response.ContentType = request.ContentType;
            response.AddHeader("Content-disposition", "attachment; filename=" + request.RawUrl.Remove(0, 1));

            writeTo(stream, response.OutputStream);

            response.StatusCode = (int)HttpStatusCode.OK;
            response.StatusDescription = "OK";

            stream.Close();
            response.Close();

            Console.WriteLine("200");
        }
开发者ID:Boberneprotiv,项目名称:FileService,代码行数:19,代码来源:FileRequest.cs

示例8: UpdateEmployee

        private void UpdateEmployee(HttpListenerRequest request, HttpListenerResponse response)
        {
            // Deserialize Employee object.
            string body = String.Empty;
            using (StreamReader reader = new StreamReader(request.InputStream))
            {
                body = reader.ReadToEnd();
            }

            Employee employee = null;
            try
            {
                if (_dataFormat == "application/xml")
                {
                    employee = UtilityXml.DeserializeXml<Employee>(body);
                }
                else if (_dataFormat == "application/json")
                {
                    employee = UtilityJson.DeserializeJson<Employee>(body);
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(@"ERROR: Failed to deserialize the Employee object - {ex.Message}");
            }

            if (employee == null)
            {
                response.StatusCode = 400;
                response.Close();
                return;
            }

            // Perform the actual update.
            _repository.Update(employee);

            // Construct and send the response.
            response.StatusCode = 200;
            response.Close();

            Console.WriteLine(@"POST: Updated employee with ID {employee.EmployeeId}");
        }
开发者ID:AlexIach,项目名称:PAD_Lab_6,代码行数:42,代码来源:HttpTransportService.cs

示例9: OnGetRequest

        public override void OnGetRequest(HttpListenerRequest request, HttpListenerResponse response)
		{
            string url = request.Url.ToString().Remove(0, host.Length - 1);
            if (url.Contains("?v")) {
                url = url.Substring(0, url.IndexOf("?v"));
            }
            string filename = AssetPath + url;

            string responseString = string.Empty;
            if (url.EndsWith("/")) {
                responseString = "<html><body><h1>SimpleFramework WebServer 0.1.0</h1>";
                responseString += "Current Time: " + DateTime.Now.ToString() + "<br>";
                responseString += "url : " + request.Url + "<br>";
                responseString += "Asset Path: " + filename;

                goto label;
            } else {
                if (File.Exists(filename)) {
                    using (Stream fs = File.Open(filename, FileMode.Open)) {
                        response.ContentLength64 = fs.Length;
                        response.ContentType = GetMimeType(filename) + "; charset=UTF-8";

                        fs.CopyTo(response.OutputStream);
                        response.OutputStream.Flush();
                        response.Close(); return;
                    }
                } else {
                    responseString = "<h1>404</h1>";
                    goto label;
                }
            }
            label: 
                try {
                    response.ContentLength64 = Encoding.UTF8.GetByteCount(responseString);
                    response.ContentType = "text/html; charset=UTF-8";
                } finally {
                    Stream output = response.OutputStream;
                    StreamWriter writer = new StreamWriter(output);
                    writer.Write(responseString);
                    writer.Close();
                }
        }
开发者ID:neutra,项目名称:uLuaGameFramework,代码行数:42,代码来源:HttpServer.cs

示例10: OnBeginGetContextReceived

        private HttpListener OnBeginGetContextReceived(IAsyncResult result)
        {
            if (_response != null)
            {
                try
                {
                    _response.Close();
                    _response = null;
                }
                catch
                { }
            }

            var context = _listener.EndGetContext(result);
            var request = context.Request;

            var url = request.Url;
            //Console.WriteLine("streaming request: " + request.Url);

            lock (_gate)
            {
                _response = context.Response;
            }
            try
            {
                SendClusterData();
            }
            catch(Exception e)
            {
                Console.WriteLine("Error sending cluster data");
                Console.WriteLine(e);

                _response.Close();
                _response = null;
            }

            return _listener;
        }
开发者ID:akutruff,项目名称:Couchbase.Net,代码行数:38,代码来源:StreamingClusterDataService.cs

示例11: SendNotModified

 public void SendNotModified(HttpListenerResponse response)
 {
     response.StatusCode = (int)HttpStatusCode.NotModified;
     response.Close();
 }
开发者ID:cannero,项目名称:restlib,代码行数:5,代码来源:ResponseWriter.cs

示例12: WriteAndFlushResponse

 void WriteAndFlushResponse(HttpListenerResponse response, byte[] buffer)
 {
     response.ContentLength64 = buffer.Length;
     using(Stream output = response.OutputStream)
     {
         output.Write(buffer, 0, buffer.Length);
     }
     response.Close();
 }
开发者ID:cannero,项目名称:restlib,代码行数:9,代码来源:ResponseWriter.cs

示例13: FinalizeAcceptedResponse

		private static void FinalizeAcceptedResponse(HttpListenerRequest request, HttpListenerResponse response, RevaleeTask task)
		{
			string remoteAddress = request.RemoteEndPoint.Address.ToString();

			try
			{
				response.StatusCode = 200;
				response.StatusDescription = "OK";
				byte[] confirmation_number = Encoding.UTF8.GetBytes(task.CallbackId.ToString());
				response.ContentLength64 = confirmation_number.LongLength;
				response.OutputStream.Write(confirmation_number, 0, confirmation_number.Length);
			}
			finally
			{
				response.Close();
			}

			Supervisor.Telemetry.RecordAcceptedRequest();
			Supervisor.LogEvent(string.Format("Request accepted for {0} @ {1:d} {1:t} from {2}. [{3}]", task.CallbackUrl.OriginalString, task.CallbackTime, remoteAddress, task.CallbackId), TraceEventType.Verbose);
		}
开发者ID:Philo,项目名称:Revalee,代码行数:20,代码来源:ScheduleRequestHandler.cs

示例14: FinalizeRejectedResponse

		private static void FinalizeRejectedResponse(HttpListenerRequest request, HttpListenerResponse response, int statusCode, string statusDescription, Uri callbackUrl)
		{
			string remoteAddress = request.RemoteEndPoint.Address.ToString();

			try
			{
				response.StatusCode = statusCode;
				response.StatusDescription = statusDescription;
			}
			finally
			{
				response.Close();
			}

			Supervisor.Telemetry.RecordRejectedRequest();
			if (callbackUrl == null)
			{
				Supervisor.LogEvent(string.Format("Request rejected from {0} due to: {1}.", remoteAddress, statusDescription), TraceEventType.Verbose);
			}
			else
			{
				Supervisor.LogEvent(string.Format("Request rejected for {0} from {1} due to: {2}.", callbackUrl.OriginalString, remoteAddress, statusDescription), TraceEventType.Verbose);
			}
		}
开发者ID:Philo,项目名称:Revalee,代码行数:24,代码来源:ScheduleRequestHandler.cs

示例15: ProcessRequest


//.........这里部分代码省略.........
                }
                else
                {
                    // In this case the message is chunk encoded, but m_httpRequest.InputStream actually does processing.
                    // So we we read until zero bytes are read.
                    bool readComplete = false;
                    int bufferSize = ReadPayload;
                    messageBuffer = new byte[bufferSize];
                    int offset = 0;
                    while (!readComplete)
                    {
                        while (offset < ReadPayload)
                        {
                            int noRead = m_httpRequest.InputStream.Read(messageBuffer, offset, messageLength - offset);
                            // If we read zero bytes - means this is end of message. This is how InputStream.Read for chunked encoded data.
                            if (noRead == 0)
                            {
                                readComplete = true;
                                break;
                            }

                            offset += noRead;
                        }

                        // If read was not complete - increase the buffer.
                        if (!readComplete)
                        {
                            bufferSize += ReadPayload;
                            byte[] newMessageBuf = new byte[bufferSize];
                            Array.Copy(messageBuffer, newMessageBuf, offset);
                            messageBuffer = newMessageBuf;
                        }
                    }

                    m_chunked = false;
                }

                // Process the soap request.
                try
                {
                    // Message byte buffer
                    byte[] soapRequest;
                    byte[] soapResponse = null;

                    // If this is an mtom message process attachments, else process the raw message
                    if (m_mtomHeader != null)
                    {
                        // Process the message
                        WsMessage response = ProcessRequestMessage(new WsMessage(messageBuffer, m_mtomHeader.boundary, m_mtomHeader.start));
                        if (response != null)
                        {

                            soapResponse = response.Message;
                            if (response.MessageType == WsMessageType.Mtom)
                            {
                                m_mtomHeader.boundary = response.BodyParts.Boundary;
                                m_mtomHeader.start = response.BodyParts.Start;
                            }
                        }
                    }
                    else
                    {
                        // Convert the message buffer to a byte array
                        soapRequest = messageBuffer;

                        // Performance debuging
                        DebugTiming timeDebuger = new DebugTiming();
                        timeDebuger.ResetStartTime("***Request Debug timer started");

                        // Process the message
                        WsMessage response = ProcessRequestMessage(new WsMessage(soapRequest));
                        if (response != null)
                            soapResponse = response.Message;

                        // Performance debuging
                        timeDebuger.PrintElapsedTime("***ProcessMessage Took");
                    }

                    // Display remote endpoint
                    System.Ext.Console.Write("Response To: " + m_httpRequest.RemoteEndPoint.ToString());

                    // Send the response
                    SendResponse(soapResponse);
                }
                catch (Exception e)
                {
                    System.Ext.Console.Write(e.Message + " " + e.InnerException);
                    SendError(400, "Bad Request");
                }
            }
            catch
            {
                System.Ext.Console.Write("Invalid request format. Request ignored.");
                SendError(400, "Bad Request");
            }
            finally
            {
                m_httpResponse.Close();
            }
        }
开发者ID:prabby,项目名称:miniclr,代码行数:101,代码来源:WsHttpServer.cs


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