I am trying to write a login script, but for some reason I am getting an internal server error (500).
I tried this with PHP and cURL, there I got a response when I set the option VERIFY_PEER = false.
Here’s the C# code:
private void Login()
{
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create("https://whatever.com");
ASCIIEncoding encoding = new ASCIIEncoding();
string postData = string.Format("user={0}&password={1}&submit=login", User, Password);
byte[] data = Encoding.ASCII.GetBytes(postData);
webRequest.Method = "POST";
ServicePointManager.ServerCertificateValidationCallback = (x,y,z,a) => true;
webRequest.ContentLength = data.Length;
webRequest.KeepAlive = false;
using (Stream stream = webRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
using (HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse())
{
using (StreamReader responseStream = new StreamReader(response.GetResponseStream()))
{
Console.WriteLine(responseStream.ReadToEnd());
}
}
}
Does anybody know why I am not getting a response?
Thanks for your help.
I found the mistake… It seems as if the server requieres a “valid” useragent. When setting firefox as a useragent, everything works fine.