Login to HTTPS captive portal
I actually connect in my univ to the network through a captive portal at this url https://secure.arubanetworks.com/cgi-bin/login, time ago I made a program to connect to it which worked perfect (C++ & libCurl), sending an HTTP POST with the needed "query string" such as username and password, but i think it was because there wasn't still the SSL, a X.509 Cert, that now seems to work with a GET instead of the POST that used before.
Pasting on Firefox the full url with the query string worked to me perfect, as it should, so i just tried to achieve that in a little C# program, but since i don't know what to do about the certificate (i asume there must be smth to do with it.. :P) it throws me a ProtocolError, and now i thought i should understand a bit about it first, so i'm interested in the code to achieve it, but also the way it works. :)
PS: Also would love if there's a way to set the account or the program (exe) as a callback, on the connection properties (my OS is Win7) so that once connected to the netwo开发者_运维问答rk im inmediatelly authenticated. :D
Thanks in advance for your time and help mates! ;)
Uri uri = new Uri(url + "?" + postData);
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(uri);
req.Method = this.method;
// ToDo: Something doesn't work with the cert auth I guess
req.Proxy = null;
req.Credentials = CredentialCache.DefaultCredentials;
ServicePointManager.ServerCertificateValidationCallback +=
delegate(object sender, X509Certificate certificate, X509Chain chain,
SslPolicyErrors sslPolicyErrors)
{
return true;
};
try
{
HttpWebResponse resp = (HttpWebResponse)req.GetResponse();
Stream responseStream = resp.GetResponseStream();
StreamReader reader = new StreamReader(responseStream);
string responseFromServer = reader.ReadToEnd();
}
catch (WebException e)
{
if (e.Status == WebExceptionStatus.ProtocolError)
{
HttpWebResponse response = e.Response as HttpWebResponse;
if (response != null)
{
Console.WriteLine(e.ToString());
}
}
}
Try this for an https GET. For reference, it's related to but simpler than doing an https POST.
There's a difference if you need an asynch approach, but I don't think that's what you need. So, you still use HttpWebRequest
object, but there's a difference after you get to the .method
-- all you should need is to stuff your uri into the request, and grab the response. I don't think you should manually need to mess with the proxy or credentials.
精彩评论