Какие бывают POST запросы и от чего зависит их содержание? - C#
Формулировка задачи:
Здравствуйте.
Расскажите пожалуйста какие бывают POST запросы и от чего их содержание зависит.
Ситуация :
Запрос посланный нажатием на кнопку ОК из Хрома срабатывает на сервере и выглядит вот так:
Запрос созданный таким методом в Standalone-приложении C# :
Выдает ошибку и выглядит так:
Очевидно что второй существенно короче и слегка отличается по структуре.
Как отослать при помощи C# такой как в первом варианте ? почему второй в такой форме?
Листинг программы
- <FORM ACTION="https://test.paysecure.ru/bill/createbill.cfm" method="POST">
- <INPUT TYPE="hidden" NAME="Merchant_ID" VALUE="561889">
- <INPUT TYPE="hidden" NAME="Login" VALUE="VoltDeMar_sale">
- <INPUT TYPE="hidden" NAME="Password" VALUE="***">
- <INPUT TYPE="hidden" NAME="Bill" VALUE="tesx98765k4778">
- <INPUT TYPE="hidden" NAME="Bill_amount" VALUE="100.00">
- <INPUT TYPE="hidden" NAME="Bill_currency" VALUE="RUB">
- <INPUT TYPE="hidden" NAME="Bill_comment" VALUE="This is test">
- <INPUT TYPE="hidden" NAME="Customer_Name" VALUE="Pokupatel">
- <INPUT TYPE="hidden" NAME="Customer_Middleтame" VALUE="Pokupatelevich">
- <INPUT TYPE="hidden" NAME="Customer_Email" VALUE="removed@mail.ru">
- <INPUT TYPE="hidden" NAME="Customer_Phone" VALUE="89202705770">
- <INPUT TYPE="hidden" NAME="Customer_Mobile" VALUE="89202705770">
- <INPUT TYPE="hidden" NAME="Pay_until" VALUE="2016-07-21 01:00:00">
- <INPUT TYPE="hidden" NAME="Language" VALUE="RU">
- <INPUT TYPE="hidden" NAME="SendNotification" VALUE="1">
- <INPUT TYPE="Submit" VALUE="OK"></FORM>
Листинг программы
- Запрос в 13:01 по мск:
- "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$$$"
Листинг программы
- BillData rd = new BillData();
- rd.Merchant_ID = textBox1.Text;
- rd.Login = textBox2.Text;
- rd.Password = textBox3.Text;
- rd.Bill = textBox4.Text; // Номер счета">
- rd.Bill_amount = textBox5.Text; // Сумма счета">
- rd.Bill_currency = textBox6.Text; //Валюта счета">
- rd.Bill_comment = textBox7.Text; //Комментарий к счету">
- rd.Customer_Name = textBox8.Text; //Имя плательщика">
- rd.Customer_Middlename = textBox9.Text; // Отчество плательщика">
- rd.Customer_Email = textBox10.Text; //Email плательщика">
- rd.Customer_Phone = textBox11.Text; //Телефон плательщика">
- rd.Customer_Mobile = textBox12.Text; //Моб. телефон плательщика">
- rd.Language = textBox13.Text; //Язык платежных страниц">
- rd.Pay_until = textBox14.Text; //Срок оплаты счета">
- rd.SendNotification = textBox15.Text; //Флаг отправки счета">
- rd.Checkvalue = textBox16.Text; //Контр
- string req = @"Merchant_ID=" + rd.Merchant_ID + @"
- &Login='" + rd.Login + @"'
- &Password='" + rd.Password+ @"'
- &Bill='" + rd.Bill + @"'
- &Bill_amount='" + rd.Bill_amount + @"'
- &Bill_currency='" + rd.Bill_currency + @"'
- &Bill_comment='" + rd.Bill_comment + @"'
- &Customer_name='" + rd.Customer_Name + @"'
- &Customer_middlename='" + rd.Customer_Middlename + @"'
- &Customer_email='" + rd.Customer_Email + @"'
- &Customer_phone='" + rd.Customer_Phone + @"'
- &Customer_mobile='" + rd.Customer_Mobile + @"'
- &Language='" + rd.Language + @"'
- &Pay_until='" + rd.Pay_until + @"'
- &Sendnotification='" + rd.SendNotification + "'";
- HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create("https://test.paysecure.ru/bill/createbill.cfm");
- UTF8Encoding encoding = new UTF8Encoding();
- hwr.ContentLength = encoding.GetByteCount(req);
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
- hwr.Method = "POST";
- using (Stream requestStream = hwr.GetRequestStream())
- {
- requestStream.Write(encoding.GetBytes(req), 0,
- encoding.GetByteCount(req));
- }
- textBox19.Text = hwr.RequestUri.AbsoluteUri;
- try
- {
- HttpWebResponse response = hwr.GetResponse() as HttpWebResponse;
- string responseBody = "";
- using (Stream rspStm = response.GetResponseStream())
- {
- using (StreamReader reader = new StreamReader(rspStm))
- {
- responseBody = reader.ReadToEnd();
- textBox18.Text = responseBody;
- }
- }
- }
- catch (Exception exc)
- {
- }
Листинг программы
- Запрос в 13:03 по мск:
- "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=
- 561889&Login=VoltDeMar_sale&password=***&Bill=010604210316&Bill_amount=100.00&Bill_currency=RUB&
- Bill_comment=This is test bill&Customer_name=Pokupatel&Customer_middlename=Pokupatelevich&
- Customer_email=removed@mail.ru&Customer_phone=89202705770&
- Customer_mobile=89202705770&Language=RU&Pay_until=2016-06-22T01:03:04&
- Sendnotification=1&checkvalue=415D463E14CB41B7274647D321BB0BA7562AEC37020AEB16D7B287B86B0B4D8B;$$$"
Запросы с того конца высланы мне тех поддержкой сервера, чем они их считывают и как мне не известно.
Решение задачи: «Какие бывают POST запросы и от чего зависит их содержание?»
textual
Листинг программы
- BillData rd = new BillData() {
- Merchant_ID = textBox1.Text,
- Login = textBox2.Text,
- Password = textBox3.Text,
- Bill = textBox4.Text, // Номер счета">
- Bill_amount = textBox5.Text, // Сумма счета">
- Bill_currency = textBox6.Text, //Валюта счета">
- Bill_comment = textBox7.Text, //Комментарий к счету">
- Customer_Name = textBox8.Text, //Имя плательщика">
- Customer_Middlename = textBox9.Text, // Отчество плательщика">
- Customer_Email = textBox10.Text, //Email плательщика">
- Customer_Phone = textBox11.Text, //Телефон плательщика">
- Customer_Mobile = textBox12.Text, //Моб. телефон плательщика">
- Language = textBox13.Text, //Язык платежных страниц">
- Pay_until = textBox14.Text, //Срок оплаты счета">
- SendNotification = textBox15.Text, //Флаг отправки счета">
- Checkvalue = textBox16.Text //Контр
- };
- Encoding reqEncoding = Encoding.UTF8;
- string req = "";
- req += "Merchant_ID=" + HttpUtility.UrlEncode(rd.Merchant_ID, reqEncoding);
- req += "&Login=" + HttpUtility.UrlEncode(rd.Login, reqEncoding);
- req += "&Password=" + HttpUtility.UrlEncode(rd.Password, reqEncoding);
- req += "&Bill=" + HttpUtility.UrlEncode(rd.Bill, reqEncoding);
- req += "&Bill_amount=" + HttpUtility.UrlEncode(rd.Bill_amount, reqEncoding);
- req += "&Bill_currency=" + HttpUtility.UrlEncode(rd.Bill_currency, reqEncoding);
- req += "&Bill_comment=" + HttpUtility.UrlEncode(rd.Bill_comment, reqEncoding);
- req += "&Customer_name=" + HttpUtility.UrlEncode(rd.Customer_Name, reqEncoding);
- req += "&Customer_middlename=" + HttpUtility.UrlEncode(rd.Customer_Middlename, reqEncoding);
- req += "&Customer_email=" + HttpUtility.UrlEncode(rd.Customer_Email, reqEncoding);
- req += "&Customer_phone=" + HttpUtility.UrlEncode(rd.Customer_Phone, reqEncoding);
- req += "&Customer_mobile=" + HttpUtility.UrlEncode(rd.Customer_Mobile, reqEncoding);
- req += "&Language=" + HttpUtility.UrlEncode(rd.Language, reqEncoding);
- req += "&Pay_until=" + HttpUtility.UrlEncode(rd.Pay_until, reqEncoding);
- req += "&Sendnotification=" + HttpUtility.UrlEncode(rd.SendNotification, reqEncoding);
- ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls11;
- HttpWebRequest hwr = (HttpWebRequest)HttpWebRequest.Create("https://test.paysecure.ru/bill/createbill.cfm");
- hwr.Method = "POST";
- using (Stream requestStream = hwr.GetRequestStream())
- {
- byte[] postData = reqEncoding.GetBytes(req);
- requestStream.Write(postData, 0, postData.Length);
- hwr.ContentLength = postData.Length;
- hwr.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
- }
- // Далее без именений ...
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д