Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Client:
- private void SendButton_Click(object sender, EventArgs e)
- {
- decimal FirstNumber = FirstNumberNumericUpDown.Value;
- decimal SecondNumber = SecondNumberNumericUpDown.Value;
- string Operator = string.Empty;
- if (AdditonRadioButton.Checked)
- {
- Operator = "+";
- }
- else if (SubtractionRadioButton.Checked)
- {
- Operator = "-";
- }
- else if (MultiplicationRadioButton.Checked)
- {
- Operator = "*";
- }
- else if (DivisionRadioButton.Checked)
- {
- Operator = "/";
- }
- string result = string.Empty;
- HttpWebRequest webRequest;
- string requestParams = "{\"FirstNumber\": "+ FirstNumber.ToString() +", \"SecondNumber\": " + SecondNumber.ToString() + ",\"Operator\": \"" + Operator + "\"}";
- webRequest = (HttpWebRequest)WebRequest.Create(UrlTextBox1.Text);
- webRequest.Method = "POST";
- webRequest.ContentType = "application/json";
- byte[] byteArray = Encoding.UTF8.GetBytes(requestParams);
- webRequest.ContentLength = byteArray.Length;
- try
- {
- using (Stream requestStream = webRequest.GetRequestStream())
- {
- requestStream.Write(byteArray, 0, byteArray.Length);
- }
- }
- catch(Exception ex)
- {
- listBox.Items.Add("Could not connect to the server");
- listBox.Items.Add("Exception: " + ex);
- return;
- }
- }
- Server:
- public void Post(Equation equation)
- {
- string directory = HttpRuntime.AppDomainAppPath;
- string text = equation.FirstNumber.ToString() + " " + equation.SecondNumber.ToString() + " " + equation.Operator;
- System.IO.File.WriteAllText(directory + "txtfile.txt", text);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement