C# 如何使用C提交https表单#
我正在创建一个C#/.NET应用程序来自动重新连接到wifi热点。互联网接入检测工作正常,但我无法重新连接。wifi热点使用HTTPS登录后表单 我尝试了stackoverflow的几个建议,但到目前为止没有任何效果:我从请求中得到的答案是登录页面,我没有连接到Internet 我试过:C# 如何使用C提交https表单#,c#,.net,forms,https,C#,.net,Forms,Https,我正在创建一个C#/.NET应用程序来自动重新连接到wifi热点。互联网接入检测工作正常,但我无法重新连接。wifi热点使用HTTPS登录后表单 我尝试了stackoverflow的几个建议,但到目前为止没有任何效果:我从请求中得到的答案是登录页面,我没有连接到Internet 我试过: public class Hotspot { public string Url { get; set; } public string Method { get; set; } pub
public class Hotspot
{
public string Url { get; set; }
public string Method { get; set; }
public string Inputs { get; set; }
public HttpStatusCode Connect()
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(this.Url);
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
request.Method = this.Method;
ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(delegate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors) { return true; });
byte[] post_bytes = Encoding.ASCII.GetBytes(this.Inputs);
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = post_bytes.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(post_bytes, 0, post_bytes.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine(new StreamReader(response.GetResponseStream()).ReadToEnd());
Console.WriteLine(response.StatusCode);
return response.StatusCode;
}
public void Connect2()
{
using (WebClient client = new WebClient())
{
client.Headers.Add(HttpRequestHeader.ContentType, "text/xml");
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] response = client.UploadData(this.Url, "POST", encoding.GetBytes(this.Inputs));
Console.WriteLine(encoding.GetString(response));
}
}
}
- 此.Url看起来像@”https://hotspot.somtehing.com/nb4_crypt.php"
- 这个方法是“POST”
- this.Inputs是一个字符串,表示所有输入及其值(如@“username=me&password=something&conditions=on&blablah=“)
我检查了输入值,它们是正确的:我可以使用web浏览器进行连接。浏览器输出什么?浏览器会用一个div重新打开登录页面,该div会屏蔽页面并停留8秒钟,告知登录成功,然后重定向到我之前询问的页面。