示例#1
0
        public void Request()
        {
            master_account_name       = _usernameInputBox.Text;
            master_account_email      = _emailInputBox.Text;
            master_account_password   = Crypt.StringToMD5(_passwordInputBox.Text);
            master_account_repassword = Crypt.StringToMD5(_passwordReInputBox.Text);

            if (_usernameInputBox.Text.Equals("") || _passwordInputBox.Text.Equals("") || _passwordReInputBox.Text.Equals("") || _emailInputBox.Text.Equals(""))
            {
                MessageBox.Show("Empty email or password! Please try again.", "Error");
                Response = "register failed!";
                return;
            }
            else
            if (master_account_name != "" && master_account_password != "" && master_account_repassword != "")
            {
                if (master_account_password != master_account_repassword)
                {
                    MessageBox.Show("password & re-password not the same! Please try again.", "Error");
                    Response = "register failed!";
                    return;
                }
                else
                {
                    if (IsValidEmail(master_account_email))
                    {
                        // Create a request using a URL that can receive a post.
                        WebRequest request = WebRequest.Create(url);
                        // Set the Method property of the request to POST.
                        request.Method = "POST";
                        // Create POST data and convert it to a byte array.
                        string postData  = "username="******"&password="******"&email=" + master_account_email;
                        byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                        // Set the ContentType property of the WebRequest.
                        request.ContentType = "application/x-www-form-urlencoded";
                        // Set the ContentLength property of the WebRequest.
                        request.ContentLength = byteArray.Length;
                        // Get the request stream.
                        Stream dataStream = request.GetRequestStream();
                        // Write the data to the request stream.
                        dataStream.Write(byteArray, 0, byteArray.Length);
                        // Close the Stream object.
                        dataStream.Close();
                        // Get the response.
                        WebResponse response = request.GetResponse();
                        // Display the status.
                        // Get the stream containing content returned by the server.
                        dataStream = response.GetResponseStream();
                        // Open the stream using a StreamReader for easy access.
                        StreamReader reader = new StreamReader(dataStream);
                        // Read the content.
                        string responseFromServer = reader.ReadToEnd();
                        // Display the content.
                        // Clean up the streams.
                        reader.Close();
                        dataStream.Close();
                        response.Close();

                        Response = responseFromServer;
                    }
                    else
                    {
                        MessageBox.Show("email is not a mail adress! Please try again.", "Error");
                        Response = "register failed!";
                        return;
                    }
                }
            }
        }