Какие бывают POST запросы и от чего зависит их содержание? - C#

Узнай цену своей работы

Формулировка задачи:

Здравствуйте. Расскажите пожалуйста какие бывают POST запросы и от чего их содержание зависит. Ситуация :
Листинг программы
  1. <FORM ACTION="https://test.paysecure.ru/bill/createbill.cfm" method="POST">
  2. <INPUT TYPE="hidden" NAME="Merchant_ID" VALUE="561889">
  3. <INPUT TYPE="hidden" NAME="Login" VALUE="VoltDeMar_sale">
  4. <INPUT TYPE="hidden" NAME="Password" VALUE="***">
  5. <INPUT TYPE="hidden" NAME="Bill" VALUE="tesx98765k4778">
  6. <INPUT TYPE="hidden" NAME="Bill_amount" VALUE="100.00">
  7. <INPUT TYPE="hidden" NAME="Bill_currency" VALUE="RUB">
  8. <INPUT TYPE="hidden" NAME="Bill_comment" VALUE="This is test">
  9. <INPUT TYPE="hidden" NAME="Customer_Name" VALUE="Pokupatel">
  10. <INPUT TYPE="hidden" NAME="Customer_Middleтame" VALUE="Pokupatelevich">
  11. <INPUT TYPE="hidden" NAME="Customer_Email" VALUE="removed@mail.ru">
  12. <INPUT TYPE="hidden" NAME="Customer_Phone" VALUE="89202705770">
  13. <INPUT TYPE="hidden" NAME="Customer_Mobile" VALUE="89202705770">
  14. <INPUT TYPE="hidden" NAME="Pay_until" VALUE="2016-07-21 01:00:00">
  15. <INPUT TYPE="hidden" NAME="Language" VALUE="RU">
  16. <INPUT TYPE="hidden" NAME="SendNotification" VALUE="1">
  17. <INPUT TYPE="Submit" VALUE="OK"></FORM>
Запрос посланный нажатием на кнопку ОК из Хрома срабатывает на сервере и выглядит вот так:
Листинг программы
  1. Запрос в 13:01 по мск:
  2. "INFO","ajp-apr-127.0.0.1-8009-exec-6","06/21/2016","10:01:53","","5C5E7BAD-BF65-4677-A20E1621347188AC: 109.111.12.136,21/06/2016 10:01:53,POST,test.paysecure.ru,80,,/bill/createbill.cfm?,Merchant_ID=561889;Bill_amount=100.00;Customer_Name=Pokupatel;password=***;fieldnames=Merchant_ID,Bill_amount,Customer_Name,Password,Login,SendNotification,Pay_until,Language,Customer_Mobile,Customer_Email,Bill_comment,Customer_Phone,Bill_currency,Customer_Middleтame,Bill;Login=VoltDeMar_sale;SendNotification=1;Pay_until=2016-07-21 01:00:00;Language=RU;Customer_Mobile=89202705770;Customer_Email=removed@mail.ru;Bill_comment=This is test;Customer_Phone=89202705770;Bill_currency=RUB;Customer_Middleтame=Pokupatelevich;Bill=tesx98765k4778,Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36,http://localhost:49642/SendReqPage.html,,$$$Merchant_ID=561889&Login=VoltDeMar_sale&password=***&Bill=tesx98765k4778&Bill_amount=100.00&Bill_currency=RUB&Bill_comment=This+is+test&Customer_Name=Pokupatel&Customer_Middle%D1%82ame=Pokupatelevich&Customer_Email=vladimir.kartashev98%40gmail.com&Customer_Phone=89202705770&Customer_Mobile=89202705770&Pay_until=2016-07-21+01%3A00%3A00&Language=RU&SendNotification=1$$$"
Запрос созданный таким методом в Standalone-приложении C# :
Листинг программы
  1. BillData rd = new BillData();
  2. rd.Merchant_ID = textBox1.Text;
  3. rd.Login = textBox2.Text;
  4. rd.Password = textBox3.Text;
  5. rd.Bill = textBox4.Text; // Номер счета">
  6. rd.Bill_amount = textBox5.Text; // Сумма счета">
  7. rd.Bill_currency = textBox6.Text; //Валюта счета">
  8. rd.Bill_comment = textBox7.Text; //Комментарий к счету">
  9. rd.Customer_Name = textBox8.Text; //Имя плательщика">
  10. rd.Customer_Middlename = textBox9.Text; // Отчество плательщика">
  11. rd.Customer_Email = textBox10.Text; //Email плательщика">
  12. rd.Customer_Phone = textBox11.Text; //Телефон плательщика">
  13. rd.Customer_Mobile = textBox12.Text; //Моб. телефон плательщика">
  14. rd.Language = textBox13.Text; //Язык платежных страниц">
  15. rd.Pay_until = textBox14.Text; //Срок оплаты счета">
  16. rd.SendNotification = textBox15.Text; //Флаг отправки счета">
  17. rd.Checkvalue = textBox16.Text; //Контр
  18. string req = @"Merchant_ID=" + rd.Merchant_ID + @"
  19. &Login='" + rd.Login + @"'
  20. &Password='" + rd.Password+ @"'
  21. &Bill='" + rd.Bill + @"'
  22. &Bill_amount='" + rd.Bill_amount + @"'
  23. &Bill_currency='" + rd.Bill_currency + @"'
  24. &Bill_comment='" + rd.Bill_comment + @"'
  25. &Customer_name='" + rd.Customer_Name + @"'
  26. &Customer_middlename='" + rd.Customer_Middlename + @"'
  27. &Customer_email='" + rd.Customer_Email + @"'
  28. &Customer_phone='" + rd.Customer_Phone + @"'
  29. &Customer_mobile='" + rd.Customer_Mobile + @"'
  30. &Language='" + rd.Language + @"'
  31. &Pay_until='" + rd.Pay_until + @"'
  32. &Sendnotification='" + rd.SendNotification + "'";
  33. HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create("https://test.paysecure.ru/bill/createbill.cfm");
  34. UTF8Encoding encoding = new UTF8Encoding();
  35. hwr.ContentLength = encoding.GetByteCount(req);
  36. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
  37. hwr.Method = "POST";
  38. using (Stream requestStream = hwr.GetRequestStream())
  39. {
  40. requestStream.Write(encoding.GetBytes(req), 0,
  41. encoding.GetByteCount(req));
  42. }
  43. textBox19.Text = hwr.RequestUri.AbsoluteUri;
  44. try
  45. {
  46. HttpWebResponse response = hwr.GetResponse() as HttpWebResponse;
  47. string responseBody = "";
  48. using (Stream rspStm = response.GetResponseStream())
  49. {
  50. using (StreamReader reader = new StreamReader(rspStm))
  51. {
  52. responseBody = reader.ReadToEnd();
  53. textBox18.Text = responseBody;
  54. }
  55. }
  56. }
  57. catch (Exception exc)
  58. {
  59. }
Выдает ошибку и выглядит так:
Листинг программы
  1. Запрос в 13:03 по мск:
  2. "INFO","ajp-apr-127.0.0.1-8009-exec-3","06/21/2016","10:03:12","","9DBF0A90-6A7D-4D02-A9D7B7006853C433: 109.111.12.136,21/06/2016 10:03:12,POST,test.paysecure.ru,80,,/bill/createbill.cfm?,,,,,$$$Merchant_ID=
  3. 561889&Login=VoltDeMar_sale&password=***&Bill=010604210316&Bill_amount=100.00&Bill_currency=RUB&
  4. Bill_comment=This is test bill&Customer_name=Pokupatel&Customer_middlename=Pokupatelevich&
  5. Customer_email=removed@mail.ru&Customer_phone=89202705770&
  6. Customer_mobile=89202705770&Language=RU&Pay_until=2016-06-22T01:03:04&
  7. Sendnotification=1&checkvalue=415D463E14CB41B7274647D321BB0BA7562AEC37020AEB16D7B287B86B0B4D8B;$$$"
Очевидно что второй существенно короче и слегка отличается по структуре. Как отослать при помощи C# такой как в первом варианте ? почему второй в такой форме?

Запросы с того конца высланы мне тех поддержкой сервера, чем они их считывают и как мне не известно.

Решение задачи: «Какие бывают POST запросы и от чего зависит их содержание?»

textual
Листинг программы
  1. BillData rd = new BillData() {
  2.     Merchant_ID = textBox1.Text,
  3.     Login = textBox2.Text,
  4.     Password = textBox3.Text,
  5.     Bill = textBox4.Text, // Номер счета">
  6.     Bill_amount = textBox5.Text, // Сумма счета">
  7.     Bill_currency = textBox6.Text, //Валюта счета">
  8.     Bill_comment = textBox7.Text, //Комментарий к счету">
  9.     Customer_Name = textBox8.Text, //Имя плательщика">
  10.     Customer_Middlename = textBox9.Text, // Отчество плательщика">
  11.     Customer_Email = textBox10.Text, //Email плательщика">
  12.     Customer_Phone = textBox11.Text, //Телефон плательщика">
  13.     Customer_Mobile = textBox12.Text, //Моб. телефон плательщика">
  14.     Language = textBox13.Text, //Язык платежных страниц">
  15.     Pay_until = textBox14.Text, //Срок оплаты счета">
  16.     SendNotification = textBox15.Text, //Флаг отправки счета">
  17.     Checkvalue = textBox16.Text //Контр
  18. };
  19.  
  20. Encoding reqEncoding = Encoding.UTF8;
  21. string req = "";
  22. req += "Merchant_ID="          + HttpUtility.UrlEncode(rd.Merchant_ID, reqEncoding);
  23. req += "&Login="               + HttpUtility.UrlEncode(rd.Login, reqEncoding);
  24. req += "&Password="            + HttpUtility.UrlEncode(rd.Password, reqEncoding);
  25. req += "&Bill="                + HttpUtility.UrlEncode(rd.Bill, reqEncoding);
  26. req += "&Bill_amount="         + HttpUtility.UrlEncode(rd.Bill_amount, reqEncoding);
  27. req += "&Bill_currency="       + HttpUtility.UrlEncode(rd.Bill_currency, reqEncoding);
  28. req += "&Bill_comment="        + HttpUtility.UrlEncode(rd.Bill_comment, reqEncoding);
  29. req += "&Customer_name="       + HttpUtility.UrlEncode(rd.Customer_Name, reqEncoding);
  30. req += "&Customer_middlename=" + HttpUtility.UrlEncode(rd.Customer_Middlename, reqEncoding);
  31. req += "&Customer_email="      + HttpUtility.UrlEncode(rd.Customer_Email, reqEncoding);
  32. req += "&Customer_phone="      + HttpUtility.UrlEncode(rd.Customer_Phone, reqEncoding);
  33. req += "&Customer_mobile="     + HttpUtility.UrlEncode(rd.Customer_Mobile, reqEncoding);
  34. req += "&Language="            + HttpUtility.UrlEncode(rd.Language, reqEncoding);
  35. req += "&Pay_until="           + HttpUtility.UrlEncode(rd.Pay_until, reqEncoding);
  36. req += "&Sendnotification="    + HttpUtility.UrlEncode(rd.SendNotification, reqEncoding);
  37.  
  38. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
  39. HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create("https://test.paysecure.ru/bill/createbill.cfm");
  40. hwr.Method = "POST";
  41. using (Stream requestStream = hwr.GetRequestStream())
  42. {
  43.     byte[] postData = reqEncoding.GetBytes(req);
  44.     requestStream.Write(postData, 0, postData.Length);
  45.    
  46.     hwr.ContentLength = postData.Length;
  47.     hwr.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
  48. }
  49.  
  50. // Далее без именений ...

ИИ поможет Вам:


  • решить любую задачу по программированию
  • объяснить код
  • расставить комментарии в коде
  • и т.д
Попробуйте бесплатно

Оцени полезность:

9   голосов , оценка 4.333 из 5

Нужна аналогичная работа?

Оформи быстрый заказ и узнай стоимость

Бесплатно
Оформите заказ и авторы начнут откликаться уже через 10 минут