Accessing via curl

1

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();
    }
    
asked by anonymous 20.04.2018 / 15:35

1 answer

0

You did not indicate Header User-Agent: . It secretly looks like the server is also expecting the format application/x-www-form-urlencoded .

I also advise you to use HttpClient which is the most recent way to make HTTP requests.

In your code it would look like this:

request.ContentType = "application/x-www-form-urlencoded";
request.UserAgent = "Lynx/3.15";

It's a challenge to make your code using HttpClient

    
21.04.2018 / 00:02