How do i send POST data to a website behind authentication?

3

Im working on a hobby project, there is this website behind authentication that allows me to generate promotional material for products (price, sale price, name etc..) i want to make a way to automate this process by taking the data from a MySQL database and passing it to the website automatically. I can read the data from the DB without a problem but im stuck on sending the POST request to the website.

The website looks like this:

Website for making the promotional material (in dutch)

enter image description here

I've used wireshark to find out what happens when you click the submit button ("voorbeeld tonen") and the http data is huge... i have attached the wireshark file so you can see it for yourself, basicly it inclused a lot of parameters.

This is the code i use for submitting the data:

            private void SendPost()
        {
            string url = "http://emte20.bek.nl/nl/publicationvariants/62422/refresh";
            using (var wb = new WebClient())
            {
                var data = new NameValueCollection();
                data["field[__PRODUCTnaam__#!#value]"] = "myUser";
                data["field[__PRODUCTomschrijving__#!#value]"] = "myPassword";



                var response = wb.UploadValues(url, "POST", data);
                string responseInString = Encoding.UTF8.GetString(response);
                richTextBox1.Text = responseInString;
            }
        }

when i try to execute the function it just gives me a 422 error:

> System.Net.WebException
  HResult=0x80131509
  Message=De externe server heeft een fout geretourneerd: (422) Unprocessable Entity.
  Source=System
  StackTrace:
   at System.Net.WebClient.UploadValues(Uri address, String method, NameValueCollection data)
   at System.Net.WebClient.UploadValues(String address, String method, NameValueCollection data)
   at StoreManager.dbmanagerform.SendPost() in C:\Users\joep\source\repos\StoreManager\StoreManager\DBmanager.cs:line 43
   at StoreManager.dbmanagerform.DBmanager_Load(Object sender, EventArgs e) in C:\Users\joep\source\repos\StoreManager\StoreManager\DBmanager.cs:line 29
   at System.Windows.Forms.Form.OnLoad(EventArgs e)
   at System.Windows.Forms.Form.OnCreateControl()
   at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
   at System.Windows.Forms.Control.CreateControl()
   at System.Windows.Forms.Control.WmShowWindow(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.Form.WmShowWindow(Message& m)
   at System.Windows.Forms.Form.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
   at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

If you need any more info please let me know because i am stuck. I've tried changing the url to just emte20.bek.nl but that returns a 404 Here is the wireshark file:link to file.io download

c#
post
asked on Stack Overflow Mar 15, 2019 by Joep Van Diessen • edited Mar 15, 2019 by htshame

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0