Ejemplo n.º 1
0
        private void DealHttpRequest(RequestStruct dataStruct)
        {
            try
            {
                ResponseStruct resdata = new ResponseStruct();
                resdata.ResponseSocket = dataStruct.RequestSocket;
                resdata.HttpVersion    = dataStruct.HttpVersion;

                string callback     = dataStruct.RequestQuerystring("callback");
                string requstWeight = dataStruct.RequestQuerystring("value");

                string response = "";

                switch (dataStruct.RequestPath)
                {
                case "/GetWeight.self":

                    if (requstWeight == _currentWeight)
                    {
                        _isHold = true;
                        _comReceivedWaitHandle.Reset();
                        _comReceivedWaitHandle.WaitOne(60 * 1000);     //阻塞
                        _isHold = false;
                    }

                    response = callback + "(" + "\"" + _currentWeight + "\"" + ")";

                    this._httpServer.SendToBrowser(resdata, response);

                    break;

                // 应答
                case "/Hello.self":
                    response = callback + "(" + "\"OK\"" + ")";
                    this._httpServer.SendToBrowser(resdata, response);
                    break;

                // 默认返回404错误
                default:
                {
                    resdata.StatusCode = "404";
                    this._httpServer.SendToBrowser(resdata, "Not Found<br>" + dataStruct.RequestUrl);
                    break;
                }
                }

                dataStruct.Close(); //关闭连接
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }
Ejemplo n.º 2
0
        private void DealRequest(RequestStruct dataStruct)
        {
            try
            {
                ResponseStruct resdata = new ResponseStruct();
                resdata.ResponseSocket = dataStruct.RequestSocket;
                resdata.HttpVersion    = dataStruct.HttpVersion;

                string callback = dataStruct.RequestQuerystring("callback");
                string response = "";

                switch (dataStruct.RequestPath)
                {
                // 打印
                case "/Print.self":
                    string url = dataStruct.RequestQuerystring("url");
                    string message;
                    DownLoadAndPrint(HttpUtility.UrlDecode(url), out message);

                    response = callback + "(" + "\"" + message + "\"" + ")";

                    this._httpServer.SendToBrowser(resdata, response);
                    break;

                // 应答
                case "/Hello.self":
                    response = callback + "(" + "\"OK\"" + ")";
                    this._httpServer.SendToBrowser(resdata, response);
                    break;

                // 默认返回404错误
                default:
                {
                    resdata.StatusCode = "404";
                    this._httpServer.SendToBrowser(resdata, "Not Found<br>" + dataStruct.RequestUrl);
                    break;
                }
                }

                dataStruct.Close(); //关闭连接
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }