我正在尝试通过c#提交帖子表单。我一直在浏览很多以前的问题,但我没有找到有效的解决方案。我想通过C#:
在SSL网址上回答以下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与它有什么关系,任何想法?
提前致谢