Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何发布httpWebRequest多部分/表单数据_C# - Fatal编程技术网

C# 如何发布httpWebRequest多部分/表单数据

C# 如何发布httpWebRequest多部分/表单数据,c#,C#,我以前从未使用过多部分/表单数据,这对我来说似乎有点棘手,我不知道如何发布所需的数据 以下是我迄今为止编写的代码: string urlRequestRegister = "http://iwebsite.com/user/register"; string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x"); CookieContainer c

我以前从未使用过多部分/表单数据,这对我来说似乎有点棘手,我不知道如何发布所需的数据

以下是我迄今为止编写的代码:

 string urlRequestRegister = "http://iwebsite.com/user/register";
            string boundary = "----------------------------" + DateTime.Now.Ticks.ToString("x");
            CookieContainer cookie = new CookieContainer();

            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(urlRequestRegister);
            request.Method = "POST";
            request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
            request.Credentials = CredentialCache.DefaultCredentials;
            request.CookieContainer = cookie;
            request.KeepAlive = true;

            byte[] boundary_bytes = System.Text.Encoding.ASCII.GetBytes("\r\n--" + boundary + "\r\n");

            string form_data_template = "Content-Disposition: form-data; name=\"{0}\"\r\n\r\n{1}";




        }
        catch (Exception error)
        {
            MessageBox.Show(error.ToString());
        }
Form_data_模板参数应该是字段的名称和值,但我真的不知道如何创建整个姿势

我只需要发布如下字段:thewebsite.com/user/register?id=value&name=value&age=value&submit=ok

我研究了一个lil。但我在网上只找到了一些复杂的东西

有人能帮我吗

谢谢

请查看或复制