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


C# IHttpResponse.Send方法代码示例

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


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

示例1: Write

 private void Write(IHttpResponse response, string text)
 {
     var writer = new StreamWriter(response.Body);
     writer.Write(text);
     writer.Flush();
     response.ContentLength = response.Body.Length;
     response.Send();
 }
开发者ID:john-guo,项目名称:hodgepodge,代码行数:8,代码来源:MyModule.cs

示例2: close

        public Striker2API.Usb usbToys; // Striker II object

        #endregion Fields

        #region Methods

        private static void close(IHttpResponse resp,string value)
        {
            resp.Connection = ConnectionType.Close;
            byte[] buffer = Encoding.UTF8.GetBytes("<html><body>"+value+"</body></html>");
            resp.Body.Write(buffer, 0, buffer.Length);
            resp.Send();
            System.Console.WriteLine("Complete");
        }
开发者ID:drewbuschhorn,项目名称:STRIKER-II---C--Webserver,代码行数:14,代码来源:Program.cs

示例3: Process

        public override bool Process(IHttpRequest request, IHttpResponse response, IHttpSession session)
        {
            if (request.UriParts.Length > 0 && request.UriParts[0] == "query")
            {
                cmanager.ProcessSession (request, session, response);

                var bodyWriter = new StreamWriter (response.Body);

                try
                {
                    var result = cmanager.SendAndReceive<QueryServerResultMessage> (new QueryServerMessage(), session);

                    JsonTextWriter writer = new JsonTextWriter (bodyWriter);
                    serializer.Serialize (writer, result);

                    #if !DEBUG
                    response.ContentType = "application/json";
                    #endif

                    response.AddHeader ("X-JSON", "true");
                }
                catch (Exception ex)
                {
                    bodyWriter.Write ("<pre>");
                    bodyWriter.Write (ex);
                    bodyWriter.Write ("</pre>");
                }

                bodyWriter.Flush();
                response.Send();

                return true;
            }

            return false;
        }
开发者ID:ermau,项目名称:Gablarski,代码行数:36,代码来源:QueryModule.cs

示例4: HandleRequest

		/// <summary>
		/// Process an incoming request.
		/// </summary>
		/// <param name="context">connection to client</param>
		/// <param name="request">request information</param>
		/// <param name="response">response that should be filled</param>
		/// <param name="session">session information</param>
		protected virtual void HandleRequest(IHttpClientContext context, IHttpRequest request, IHttpResponse response,
											 IHttpSession session)
		{
			_logWriter.Write(this, LogPrio.Trace, "Processing request....");
			bool handled = false;
			try
			{
				DecodeBody(request);
				if (ProcessAuthentication(request, response, session))
				{
					foreach (HttpModule module in _modules)
					{
						if (!module.Process(request, response, session))
							continue;

						handled = true;
						if (!module.AllowSecondaryProcessing)
							break;
					}
				}
			}
			catch (HttpException err)
			{
				if (err.HttpStatusCode == HttpStatusCode.Unauthorized)
				{
					AuthenticationModule mod;
					lock (_authModules)
						mod = _authModules.Count > 0 ? _authModules[0] : null;

					if (mod != null)
						RequestAuthentication(mod, request, response);
				}
				else
					ErrorPage(response, err);
			}

			if (!handled && response.Status == HttpStatusCode.OK)
				ErrorPage(response, HttpStatusCode.NotFound, "Resource not found: " + request.Uri);

			if (!response.HeadersSent)
			{
				// Dispose session if it was not used.
				if (session.Count > 0)
				{
					_sessionStore.Save(session);
					// only set session cookie if it have not been sent in the request.
					if (request.Cookies[_sessionCookieName] == null)
						response.Cookies.Add(new ResponseCookie(_sessionCookieName, session.Id, DateTime.MinValue));//DateTime.Now.AddMinutes(20).AddDays(1)));
				}
				else
					_sessionStore.AddUnused(session);
			}

			if (!response.Sent)
				response.Send();

			_logWriter.Write(this, LogPrio.Trace, "....done.");
		}
开发者ID:kf6kjg,项目名称:halcyon,代码行数:65,代码来源:HttpServer.cs

示例5: SafeSendResponse

 protected void SafeSendResponse(IHttpResponse response)
 {
   try
   {
     response.Send();
   }
   catch (IOException) { }
 }
开发者ID:chekiI,项目名称:MediaPortal-2,代码行数:8,代码来源:UPnPServer.cs

示例6: FireRequestCallback

        void FireRequestCallback(IHttpClientContext client, IHttpRequest request, IHttpResponse response, HttpRequestCallback callback)
        {
            bool closeConnection = true;

            try { closeConnection = callback(client, request, response); }
            catch (Exception ex) { _logWriter.Write(this, LogPrio.Error, "Exception in HTTP handler: " + ex.Message); }

            if (closeConnection)
            {
                try { response.Send(); }
                catch (Exception ex)
                {
                    _logWriter.Write(this, LogPrio.Error, String.Format("Failed to send HTTP response for request to {0}: {1}",
                        request.Uri, ex.Message));
                }
            }
        }
开发者ID:3di,项目名称:3di-viewer-rei-libs,代码行数:17,代码来源:WebServer.cs

示例7: FireRequestCallback

        private void FireRequestCallback(IHttpClientContext client, IHttpRequest request, IHttpResponse response, HttpRequestHandler handler)
        {
            try
            {
                handler.Callback(client, request, response);
            }
            catch (Exception ex)
            {
                m_log.Error("Exception in HTTP handler: " + ex);
                response.Status = HttpStatusCode.InternalServerError;
                response.Send();
            }

            if (handler.SendResponseAfterCallback && !response.Sent)
            {
                try { response.Send(); }
                catch (Exception ex) { m_log.ErrorFormat("Failed to send HTTP response for request to {0}: {1}", request.Uri, ex.Message); }
            }

            request.Clear();
        }
开发者ID:thoys,项目名称:simian,代码行数:21,代码来源:HttpListener.cs

示例8: CapsCallback

        void CapsCallback(IHttpClientContext client, IHttpRequest request, IHttpResponse response)
        {
            UUID capsID;
            CapsRedirector redirector;
            bool success;

            string path = request.Uri.PathAndQuery.TrimEnd('/');

            if (UUID.TryParse(path.Substring(path.Length - 36), out capsID))
            {
                lock (syncRoot)
                    success = (expiringCaps.TryGetValue(capsID, out redirector) || fixedCaps.TryGetValue(capsID, out redirector));

                if (success)
                {
                    if (redirector.ClientCertRequired)
                    {
                        success = false;
                        // FIXME: Implement this
                        /*X509Certificate2 clientCert = request.GetClientCertificate();
                        if (clientCert != null)
                        {
                            Logger.Log.Info(clientCert.ToString());
                        }*/
                    }

                    if (redirector.RemoteHandler != null)
                        ProxyCapCallback(client, request, response, redirector.RemoteHandler);
                    else
                        redirector.LocalCallback(client, request, response, redirector.State);

                    if (redirector.SendResponseAfterCallback && !response.Sent)
                        response.Send();
                    return;
                }
            }

            response.Status = HttpStatusCode.NotFound;
            response.Send();
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:40,代码来源:CapsServer.cs

示例9: ProxyCapCallback

        void ProxyCapCallback(IHttpClientContext client, IHttpRequest request, IHttpResponse response, Uri remoteHandler)
        {
            const int BUFFER_SIZE = 2048;
            int numBytes;
            byte[] buffer = new byte[BUFFER_SIZE];

            // Proxy the request
            HttpWebRequest remoteRequest = (HttpWebRequest)HttpWebRequest.Create(remoteHandler);

            remoteRequest.Method = request.Method;
            remoteRequest.Headers.Add(request.Headers);

            // TODO: Support for using our own client certificate during the proxy

            if (request.Body.Length > 0)
            {
                // Copy the request stream
                using (Stream writeStream = remoteRequest.GetRequestStream())
                {
                    while ((numBytes = request.Body.Read(buffer, 0, BUFFER_SIZE)) > 0)
                        writeStream.Write(buffer, 0, numBytes);
                }
            }

            // Proxy the response
            HttpWebResponse remoteResponse = (HttpWebResponse)remoteRequest.GetResponse();

            response.Status = remoteResponse.StatusCode;
            response.Reason = remoteResponse.StatusDescription;

            for (int i = 0; i < remoteResponse.Headers.Count; i++)
                response.AddHeader(remoteResponse.Headers.GetKey(i), remoteResponse.Headers[i]);

            // Copy the response stream
            using (Stream readStream = remoteResponse.GetResponseStream())
            {
                while ((numBytes = readStream.Read(buffer, 0, BUFFER_SIZE)) > 0)
                    response.Body.Write(buffer, 0, numBytes);
            }

            response.Send();
        }
开发者ID:RavenB,项目名称:gridsearch,代码行数:42,代码来源:CapsServer.cs

示例10: WriteAndFlush

 protected static void WriteAndFlush(IHttpResponse response, string body)
 {
     var writer = new StreamWriter (response.Body);
     writer.WriteLine (body);
     writer.Flush();
     response.Send();
 }
开发者ID:ermau,项目名称:Gablarski,代码行数:7,代码来源:SectionModule.cs

示例11: EventQueueHandler

        private void EventQueueHandler(Capability cap, IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            // Decode the request
            OSD osdRequest = null;

            try { osdRequest = OSDParser.Deserialize(request.Body); }
            catch (Exception) { }

            if (request != null && osdRequest.Type == OSDType.Map)
            {
                OSDMap requestMap = (OSDMap)osdRequest;
                int ack = requestMap["ack"].AsInteger();
                bool done = requestMap["done"].AsBoolean();

                LLAgent agent = null;

                // Fetch an agent reference from either the scene or the LLUDP stack (since the
                // presence might not exist in the scene yet)
                IScenePresence presence;
                if (m_scene.TryGetPresence(cap.OwnerID, out presence) && presence is LLAgent)
                    agent = (LLAgent)presence;
                else
                    m_udp.TryGetAgent(cap.OwnerID, out agent);

                if (agent != null)
                {
                    if (agent.EventQueue.ConnectionOpen)
                    {
                        m_log.Debug("New connection opened to the event queue for " + agent.Name + " while a previous connection is open. Closing old connection");

                        // If the old connection is still open, queue a signal to close it. Otherwise, just wait for the closed
                        // connection to be detected by the handler thread
                        if (agent.EventQueue.Response != null)
                            agent.EventQueue.EventQueue.Enqueue(null);

                        while (agent.EventQueue.ConnectionOpen)
                            Thread.Sleep(50);

                        m_log.Debug("Old event queue connection closed for " + agent.Name);
                    }

                    if (!done)
                    {
                        m_log.Debug("Opening event queue connection for " + agent.Name);

                        agent.EventQueue.Context = context;
                        agent.EventQueue.Request = request;
                        agent.EventQueue.Response = response;
                        agent.EventQueue.StartTime = Environment.TickCount & Int32.MaxValue;
                        agent.EventQueue.ConnectionOpen = true;

                        // ACK sanity checking
                        if (ack != agent.EventQueue.CurrentID - 1 && ack != 0)
                            m_log.WarnFormat("Received an ack for id {0}, last id sent was {1}", ack, agent.EventQueue.CurrentID - 1);
                    }
                    else
                    {
                        m_log.DebugFormat("Shutting down the event queue {0} for {1} at the client's request", request.Uri, agent.Name);
                        agent.EventQueue.SendEvents(50);
                    }
                }
                else
                {
                    m_log.Warn("Received an event queue connection from client " + cap.OwnerID + " that does not have a presence in scene " + m_scene.Name);
                }
            }
            else
            {
                m_log.Warn("Received a request with invalid or missing data at " + request.Uri + ", closing the connection");

                response.Connection = request.Connection;
                response.Status = System.Net.HttpStatusCode.BadRequest;
                response.Send();
            }
        }
开发者ID:osgrid,项目名称:openmetaverse,代码行数:75,代码来源:EventQueueGet.cs

示例12: RouteLocalCapability

        private void RouteLocalCapability(Capability cap, CapabilityCallback callback, IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            callback(cap, context, request, response);

            if (cap.SendResponseAfterCallback && !response.Sent)
            {
                try { response.Send(); }
                catch (Exception ex) { m_log.ErrorFormat("Failed to send HTTP response for request to capability {0}: {1}", request.Uri, ex.Message); }
            }
        }
开发者ID:thoys,项目名称:simian,代码行数:10,代码来源:CapabilityRouter.cs

示例13: RouteCapability

        /// <summary>
        /// Routes an incoming HTTP capability request to an internal method or a remote resource
        /// </summary>
        /// <param name="context">HTTP context</param>
        /// <param name="request">HTTP request</param>
        /// <param name="response">HTTP response</param>
        public void RouteCapability(IHttpClientContext context, IHttpRequest request, IHttpResponse response)
        {
            UUID capabilityID;
            string path = request.Uri.AbsolutePath.TrimEnd('/');

            if (UUID.TryParse(path.Substring(path.Length - 36), out capabilityID))
            {
                Capability cap = null;
                CapabilityCallback callback = null;

                m_capSyncRoot.EnterReadLock();
                try
                {
                    if (m_capabilities.TryGetValue(capabilityID, out cap))
                    {
                        if (cap.OneTimeResource != null)
                            callback = cap.OneTimeResource;
                        else
                            m_protectedResources.TryGetValue(cap.Resource, out callback);
                    }
                }
                finally { m_capSyncRoot.ExitReadLock(); }

                if (cap != null)
                {
                    if (callback != null)
                    {
                        RouteLocalCapability(cap, callback, context, request, response);

                        if (cap.OneTimeResource != null)
                        {
                            // This was a one time resource, destroy it
                            RemoveCapability(cap.ID);
                        }

                        return;
                    }
                    else if (cap.Resource.StartsWith("https://") || cap.Resource.StartsWith("http://"))
                    {
                        RouteRemoteCapability(cap, context, request, response);
                        return;
                    }
                    else
                    {
                        m_log.Warn("Capability " + cap.ID + " owned by " + cap.OwnerID + " maps to missing resource " + cap.ResourceDisplayName);
                    }
                }
            }

            // Return a 404
            m_log.Warn("Returning 404 for capability request to " + request.Uri);
            response.Status = System.Net.HttpStatusCode.NotFound;
            try { response.Send(); }
            catch (Exception ex) { m_log.ErrorFormat("Failed to send HTTP response for request to (missing) capability {0}: {1}", request.Uri, ex.Message); }
        }
开发者ID:thoys,项目名称:simian,代码行数:61,代码来源:CapabilityRouter.cs

示例14: Process

        public override bool Process(IHttpRequest request, IHttpResponse response, IHttpSession session)
        {
            if (request.UriParts.Length == 0)
                return false;

            string file = request.UriParts[request.UriParts.Length - 1];

            if (file.Contains ("."))
            {
                response.ContentType = GetMimeType (file);

                byte[] fileContents = GetFile (file);
                if (fileContents == null)
                {
                    response.Status = HttpStatusCode.NotFound;
                    return true;
                }

                response.Body.Write(fileContents, 0, fileContents.Length);
                response.Body.Flush();

                response.Send();

                return true;
            }

            return false;
        }
开发者ID:ermau,项目名称:Gablarski,代码行数:28,代码来源:FileResourceModule.cs


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