0

I'm trying to submit a post form via c#. I've been browsing a lot of previous questions and i did not come to a working solution. I'd like to answer the following html form on a SSL url via C#:

<form action="/start/" method="post">
    <input name="formtoken" type="hidden" value="SignupForm">
    <input id="Email" name="Email" placeholder="Enter email address" type="text" value="">
    <input autocomplete="off" id="Username" name="Username" placeholder="Enter username"     type="text" value="">
    <input autocomplete="off" id="Password" name="Password" placeholder="Enter password" type="password">
    <input autocomplete="off" id="PasswordRetype" name="PasswordRetype" placeholder="Retype Password" type="password">
</form>

By modifying the following c# code which i found on another stackoverflow question:

    static void Main(string[] args)
    {
        HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://url.com/start/");

        request.Method = "POST";
        request.ContentType = "application/x-www-form-urlencoded";
        string postData = "formtoken=SignupForm&Email=sdfjsdfkhdsf2332@gmail.com?Username=test123?Password=testpw123?PasswordRetype=testpw123";
        byte[] bytes = Encoding.UTF8.GetBytes(postData);
        request.ContentLength = bytes.Length;

        Stream requestStream = request.GetRequestStream();
        requestStream.Write(bytes, 0, bytes.Length);
        requestStream.Close();

        WebResponse response = request.GetResponse();
        Stream stream = response.GetResponseStream();
        StreamReader reader = new StreamReader(stream);

        var result = reader.ReadToEnd();
        stream.Dispose();
        reader.Dispose();
    }

The result returns the previous page containing the form. I've checked the postData var to be correct by verifying it with a manual input via chromes network tool. I'm suspecting SSL has something to do with it, any ideas?

Thanks in advance

Daenerys
  • 1
  • 1
  • 1
  • What does the form do when you click your submit button? If the form submit then display the same form, this is the reason why the result is the same form on your c# code – atbebtg Mar 13 '13 at 15:49
  • It should load the same form with the message: registration success. – Daenerys Mar 13 '13 at 16:06
  • Been browsing a bit more. Most people seems to have this problem as soon as https is involved. I tried adding certificates to be allowed without success. – Daenerys Mar 13 '13 at 19:55
  • Worked around it by filling in via webbrowser found: http://stackoverflow.com/questions/8425593/c-sharp-httpwebrequest-post-login-to-facebook – Daenerys Mar 20 '13 at 14:56

0 Answers0