1

I've never used multipart/form-data before and it seems a little tricky to me and I can't understand how to post the required data.

Here is the code I've written so far:

 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_template parameters should be the name of the field and the value but I really don't know how I'm supposed to create the entire PostURL.

I need to post only fields like : thewebsite.com/user/register?id=value&name=value&age=value&submit=ok

I've researched a lil. bit but I've found only complicated things on the internet.

Could someone help me?

Thanks

Jack
  • 13
  • 1
  • 5
  • please, take a look on [Joshcodes' answer](http://stackoverflow.com/questions/1131425/send-a-file-via-http-post-with-c-sharp) or [this](http://stackoverflow.com/questions/566462/upload-files-with-httpwebrequest-multipart-form-data) – Sergey Jul 19 '14 at 11:46
  • possible duplicate of [c# multipart/form-data submit programmatically](http://stackoverflow.com/questions/2035229/c-sharp-multipart-form-data-submit-programmatically) – Brad Rem Jul 19 '14 at 11:49

0 Answers0