Ejemplo n.º 1
0
        protected void OnQueryEvent(WebEVentArgs e)
        {
            if (null == QueryEvent)
            {
                return;
            }

            QueryEvent(this, e);
        }
Ejemplo n.º 2
0
        private void ListenerCallback(IAsyncResult iResult)
        {
            HttpListener listener = (HttpListener)iResult.AsyncState;

            if (!listener.IsListening)
            {
                return;
            }

            // Call EndGetContext to complete the asynchronous operation.

            HttpListenerContext context = listener.EndGetContext(iResult);
            HttpListenerRequest request = context.Request;

            if (request.HttpMethod.ToUpper() == "POST" && request.HasEntityBody)
            {
                Stream       body    = request.InputStream;
                Encoding     coding  = request.ContentEncoding;
                StreamReader reader  = new StreamReader(body, coding);
                string       strBody = reader.ReadToEnd();

                body.Close();
                reader.Close();

                //System.Diagnostics.Debug.Print( "Server" );
                //System.Diagnostics.Debug.Print(strBody);

                WebEVentArgs e = new WebEVentArgs();
                e.QueryString = strBody;
                OnQueryEvent(e);
            }
            // Obtain a response object.

            HttpListenerResponse response = context.Response;

            response.Close();

            // Construct a response.
#if false
            string responseString = "<HTML><BODY> Hello world!</BODY></HTML>";
            byte[] buffer         = Encoding.UTF8.GetBytes(responseString);
            // Get a response stream and write the response to it.

            response.ContentLength64 = buffer.Length;
            System.IO.Stream output = response.OutputStream;
            output.Write(buffer, 0, buffer.Length);
            // You must close the output stream.

            output.Close();
#endif
            if (listener.IsListening)
            {
                listener.BeginGetContext(webAsyncCallback, listener);
            }
        }