Advertisement
Guest User

Untitled

a guest
Dec 16th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. Client:
  2. private void SendButton_Click(object sender, EventArgs e)
  3. {
  4. decimal FirstNumber = FirstNumberNumericUpDown.Value;
  5. decimal SecondNumber = SecondNumberNumericUpDown.Value;
  6. string Operator = string.Empty;
  7.  
  8. if (AdditonRadioButton.Checked)
  9. {
  10. Operator = "+";
  11. }
  12. else if (SubtractionRadioButton.Checked)
  13. {
  14. Operator = "-";
  15. }
  16. else if (MultiplicationRadioButton.Checked)
  17. {
  18. Operator = "*";
  19. }
  20. else if (DivisionRadioButton.Checked)
  21. {
  22. Operator = "/";
  23. }
  24.  
  25. string result = string.Empty;
  26. HttpWebRequest webRequest;
  27.  
  28. string requestParams = "{\"FirstNumber\": "+ FirstNumber.ToString() +", \"SecondNumber\": " + SecondNumber.ToString() + ",\"Operator\": \"" + Operator + "\"}";
  29.  
  30. webRequest = (HttpWebRequest)WebRequest.Create(UrlTextBox1.Text);
  31.  
  32. webRequest.Method = "POST";
  33. webRequest.ContentType = "application/json";
  34.  
  35. byte[] byteArray = Encoding.UTF8.GetBytes(requestParams);
  36. webRequest.ContentLength = byteArray.Length;
  37. try
  38. {
  39. using (Stream requestStream = webRequest.GetRequestStream())
  40. {
  41. requestStream.Write(byteArray, 0, byteArray.Length);
  42. }
  43. }
  44. catch(Exception ex)
  45. {
  46. listBox.Items.Add("Could not connect to the server");
  47. listBox.Items.Add("Exception: " + ex);
  48. return;
  49. }
  50. }
  51.  
  52. Server:
  53.  
  54. public void Post(Equation equation)
  55. {
  56.  
  57. string directory = HttpRuntime.AppDomainAppPath;
  58.  
  59. string text = equation.FirstNumber.ToString() + " " + equation.SecondNumber.ToString() + " " + equation.Operator;
  60. System.IO.File.WriteAllText(directory + "txtfile.txt", text);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement