asp.net posting data by HttpWebRequest to a php site
<p>i am trying to post data to a php site from my .aspx page.
The php site takes data in two steps. In first step of php site there are 4-text boxes and 3-check boxes and 1-dropdown, all fields are mandatory.
anybody please help.
Thanks in advance.</p>

<pre><code>    string boundary = Guid.NewGuid().ToString();
    CookieContainer cookies = new CookieContainer();
    HttpWebRequest request = HttpWebRequest.Create("http://www.abc.com/JobsiteCandidates/Register.php") as HttpWebRequest;
</code></pre>

<p>here is my code</p>

<p>#region</p>

<pre><code>    request.Method = "POST";
    request.ContentType = string.Format("multipart/form-data; boundary={0}", boundary);
   // request.PreAuthenticate = true;
    request.CookieContainer = cookies;       
    StringBuilder sb = new StringBuilder();



    sb.AppendFormat("--{0}", boundary);
    sb.AppendFormat("\r\n");
    sb.AppendFormat("Content-Disposition: form-data; name=\"RegisterFirstName\"");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("Mrs");
    sb.AppendFormat("\r\n");

    sb.AppendFormat("--{0}", boundary);
    sb.AppendFormat("\r\n");
    sb.AppendFormat("Content-Disposition: form-data; name=\"RegisterLastName\"");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("title");
    sb.AppendFormat("\r\n");

    sb.AppendFormat("--{0}", boundary);
    sb.AppendFormat("\r\n");
    sb.AppendFormat("Content-Disposition: form-data; name=\"RegisterEmailAddress\"");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("mark.williams@fiveriverssupport.net");
    sb.AppendFormat("\r\n");

    sb.AppendFormat("--{0}", boundary);
    sb.AppendFormat("\r\n");
    sb.AppendFormat("Content-Disposition: form-data; name=\"RegisterPassword\"");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("123456789");
    sb.AppendFormat("\r\n");

    sb.AppendFormat("--{0}", boundary);
    sb.AppendFormat("\r\n");
    sb.AppendFormat("Content-Disposition: form-data; name=\"RegisterPasswordConfirm\"");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("123456789");
    sb.AppendFormat("\r\n");

    sb.AppendFormat("--{0}", boundary);
    sb.AppendFormat("\r\n");
    sb.AppendFormat("Content-Disposition: form-data; name=\"RegisterHomeLocation\"");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("b27 7xu");
    sb.AppendFormat("\r\n");

    sb.AppendFormat("--{0}", boundary);
    sb.AppendFormat("\r\n");
    sb.AppendFormat("Content-Disposition: form-data; name=\"RegisterReferer\"");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("17");
    sb.AppendFormat("\r\n");

    sb.AppendFormat("--{0}", boundary);
    sb.AppendFormat("\r\n");
    sb.AppendFormat("Content-Disposition: form-data; name=\"RegisterAcceptTerms\"");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("\r\n");
    sb.AppendFormat("0");
    sb.AppendFormat("\r\n");     

    #endregion

    sb.AppendFormat("--{0}--", boundary);
    byte[] fulldata = Encoding.Default.GetBytes(sb.ToString());
    request.ContentLength = fulldata.Length;
    using (Stream sw = request.GetRequestStream())
    {
        sw.Write(fulldata, 0, fulldata.Length);
    }
    HttpWebResponse response = request.GetResponse() as HttpWebResponse;
    using (StreamReader sr = new StreamReader(response.GetResponseStream()))
    {
       HttpContext.Current.Response.Write(sr.ReadToEnd());         

    }
}
</code></pre>
