0

我正在尝试通过 c# 提交一个帖子表单。我一直在浏览很多以前的问题,但我没有找到可行的解决方案。我想通过 C# 在 SSL url 上回答以下 html 表单:

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

通过修改我在另一个 stackoverflow 问题上找到的以下 c# 代码:

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

结果返回包含表单的上一页。我通过 chromes 网络工具手动输入验证了 postData var 是否正确。我怀疑 SSL 与它有关,有什么想法吗?

提前致谢

4

0 回答 0