0

Guys I try to login to http://waec2013.com/waecexam/ website by using

  1. HttpWebRequest
  2. CookieContainer

There is another technique I can use webbrowser but as this is web application so I cannot use webbrowser. But no luck is this possible that I can login to that website and get the specific data?

I do reverse engineering and do some coding but not achieve my result.

Any Suggestions

     string formUrl = "http://waec2013.com/waecexam/"; 
     string formParams = string.Format("adminName={0}&adminPass={1}&act={2}",
     "passwaec", "cee660","login");
     string cookieHeader;
     WebRequest req = WebRequest.Create(formUrl);
     req.ContentType = "application/x-www-form-urlencoded";
     req.Method = "POST";
     byte[] bytes = Encoding.ASCII.GetBytes(formParams);
     req.ContentLength = bytes.Length;
     using (Stream os = req.GetRequestStream())
     {
         os.Write(bytes, 0, bytes.Length);
     }
     WebResponse resp = req.GetResponse();
     cookieHeader = resp.Headers["Set-cookie"];

     string pageSource;
     string getUrl = "http://waec2013.com/waecexam/Leads.php";
     WebRequest getRequest = WebRequest.Create(getUrl);
     getRequest.Headers.Add("Cookie", cookieHeader);
     WebResponse getResponse = getRequest.GetResponse();
     using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
     {
        pageSource = sr.ReadToEnd();
    }
4
  • 2
    Use fiddler to examine/reverse eningeer all http trafic and then buildup again with the technique you already discovered. Commented Feb 11, 2013 at 20:43
  • Any Example That can help me Commented Feb 11, 2013 at 23:31
  • From the above code I didn't get the cookie value, it returns me null Commented Feb 12, 2013 at 7:15
  • Still didn't get anything, I am stuck here can you plz try this function and get any result, its really helpful. Commented Feb 12, 2013 at 10:03

2 Answers 2

1

Finally I have resolve my own question and post for you guys if you need it.

 public class CookiesAwareWebClient : WebClient
 {
    public CookieContainer CookieContainer { get; private set; }

    public CookiesAwareWebClient()
    {
        CookieContainer = new CookieContainer();
    }

    protected override WebRequest GetWebRequest(Uri address)
    {
        var request = base.GetWebRequest(address);
        ((HttpWebRequest)request).CookieContainer = CookieContainer;
        return request;
    }
  }

   using (var client = new CookiesAwareWebClient())
    {
        var values = new NameValueCollection
        {
            { "adminName", "passwaec" },
            { "adminPass", "cee660" },
            { "x", "0" }, 
            { "y", "0" }, 
            { "act", "login" },
        };

        // We authenticate first
        client.UploadValues("http://waec2013.com/waecexam/index.php", values);

        // Now we can download
        client.DownloadFile("http://waec2013.com/waecexam/leadExp.php?act=export",
        @"c:\abc.txt");
      }
Sign up to request clarification or add additional context in comments.

Comments

0

Add this at the start of your method:

var cookies = new CookieContainer();

After each line where you create a webrequest assing the cookies to the instantiated request:

WebRequest req = WebRequest.Create(formUrl);
req.CookieContainer = cookies;

This will store any incoming cookies and send all cookies in the container to the webserver when GETing POSTing.

You don't need to use the Set-Cookie header in that case.

1 Comment

Still did'nt get any result, I try my level best, may be I have some understanding issue. Can you plz try above code and correct me.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.