I have the following challenge:
Log in to a site with the following data:
POST */kodoreq.php HTTP/1.1
Host: eofclub.in
Cookie: logado=sim
User-Agent: Lynx/3.15
usuario=desafio&senha=987654321&submit=sim
I've tried it in several ways and I can not do it.
class Program
{
static void Main(string[] args)
{
string usuario = "desafio";
string senha = "987654321";
string submit = "sim";
System.Net.ServicePointManager.Expect100Continue = false;
Uri url = new Uri("http://eofclub.in/desafio/kodo/35p42s5436po63nnsr9o20rssp6647q3/kodoreq.php");
UTF8Encoding encoding = new UTF8Encoding();
string postData = "{ \"usuario\" : \"" + usuario + "\", \"senha\": \"" + senha + "\", \"submit\": \"" + submit + "\"}";
byte[] data = Encoding.GetEncoding("UTF-8").GetBytes(postData);
CookieContainer cookieContainer = new CookieContainer();
Cookie usuarioCookie = new Cookie("logado", "sim", "/") { Domain = url.Host };
cookieContainer.Add(usuarioCookie);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
request.CookieContainer = cookieContainer;
request.Method = "POST";
request.ContentType = "application/json";
request.UserAgent = "Lynx/3.15";
request.ContentLength = data.Length;
Stream stream = request.GetRequestStream();
stream.Write(data, 0, data.Length);
stream.Close();
WebResponse response = request.GetResponse();
stream = response.GetResponseStream();
StreamReader sr = new StreamReader(stream);
Console.WriteLine(sr.ReadToEnd());
sr.Close();
stream.Close();
Console.ReadKey();
}