如何通过身份验证将POST数据发送到网站?

时间:2019-03-15 12:57:56

标签: c# post

我正在从事一个业余项目,身份验证后有一个网站,该网站使我能够生成产品的促销材料(价格,销售价格,名称等。)我想通过获取数据来实现此过程的自动化从MySQL数据库中自动将其传递到网站。我可以毫无问题地从数据库中读取数据,但无法将POST请求发送到网站。

网站看起来像这样:

制作宣传材料的网站(荷兰语)

enter image description here

我已经使用wireshark来了解当您单击“提交”按钮(“ voorbeeld tonen”)并且http数据很大时发生了什么...我已经附加了wireshark文件,因此您基本上可以自己查看它包括很多参数。

这是我用于提交数据的代码:

            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;
            }
        }

当我尝试执行该功能时,它只会给我422错误:

> 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)

如果您需要更多信息,请让我知道,因为我被卡住了。我尝试将网址更改为emte20.bek.nl,但返回404 这是wireshark文件:link to file.io download

0 个答案:

没有答案