예제 #1
0
        /// <summary>
        /// POST Operation
        /// </summary>
        /// <param name="context"></param>
        private void CREATE(HttpContext context)
        {
            try
            {
                // HTTP POST sends name/value pairs to a web server
                // dat is sent in message body

                //The most common use of POST, by far, is to submit HTML form data to CGI scripts.

                // This Post task handles cookies and remembers them across calls.
                // This means that you can post to a login form, receive authentication cookies,
                // then subsequent posts will automatically pass the correct cookies.
                // The cookies are stored in memory only, they are not written to disk and
                // will cease to exist upon completion of the build.

                // The POST Request structure - Typical POST Request
                // POST /path/script.cgi HTTP/1.0
                // From: [email protected]
                // User-Agent: HTTPTool/1.0
                // Content-Type: application/x-www-form-urlencoded
                // Content-Length: 32

                // home=Cosby&favorite+flavor=flies

                // Extract the content of the Request and make a employee class
                // The message body is posted as bytes. read the bytes
                byte[] PostData = context.Request.BinaryRead(context.Request.ContentLength);
                //Convert the bytes to string using Encoding class
                string str = Encoding.UTF8.GetString(PostData);
                // deserialize xml into employee class
                Company.Employee emp = Deserialize(PostData);
                // Insert data in database
                dal.AddEmployee(emp);
            }
            catch (Exception ex)
            {
                WriteResponse("Error in CREATE");
                errHandler.ErrorMessage = dal.GetException();
                errHandler.ErrorMessage = ex.Message.ToString();
            }
        }