Click here to Skip to main content
16,012,611 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
I need help loging into Fileserve.com,
I want to get to a specific page behind the login,

can you see an error with this code:

C#
CookieContainer cookieContainer = new CookieContainer();
                    string html;
                    string loginData = "POSTDATA=loginUserName" + usrnm + "&loginUserPassword=" + pswrd + "&autoLogin=on&&ppp=102&loginFormSubmit=Login";

                    // First hit the login page
                    HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create("http://fileserve.com/index.php");
                    req.CookieContainer = cookieContainer;
                    req.Method = "POST";
                    req.ContentType = "application/x-www-form-urlencoded";
                    ASCIIEncoding encoding = new ASCIIEncoding();
                    byte[] loginDataBytes = encoding.GetBytes(loginData);
                    req.ContentLength = loginDataBytes.Length;
                    Stream stream = req.GetRequestStream();
                    stream.Write(loginDataBytes, 0, loginDataBytes.Length);
                    stream.Close();
                    HttpWebResponse res = (HttpWebResponse)req.GetResponse();

                    // Packe den Content der Seite die hinter der Authenifizierung liegt
                    req = (HttpWebRequest)HttpWebRequest.Create("http://fileserve.com/file-manager.php");
                    req.CookieContainer = cookieContainer;
                    req.Method = "GET";
                    res = (HttpWebResponse)req.GetResponse();
                    StreamReader sr = new StreamReader(res.GetResponseStream());
                    html = sr.ReadToEnd();
                // richTextBox1.Text = html;


I only get the login page not the one I want,I used Tamper to get the Post Parameters & Values.

for those who knows jdownloader (Filehosting app written in Java), I took a look at the fileserve plugin there and tried to change my logindata to equal it with the jdownloader data


Java
setBrowserExclusive();
       br.setFollowRedirects(true);
       br.postPage("http://fileserve.com/login.php", "loginUserName=" + Encoding.urlEncode(account.getUser()) + "&loginUserPassword=" + Encoding.urlEncode(account.getPass()) + "&autoLogin=on&loginFormSubmit=Login");
       br.getPage("http://fileserve.com/dashboard.php");
       String accType = br.getRegex("<h5>Account type:</h5>[\r\n ]+<h3>(Premium|Free)</h3>").getMatch(0);



now loginData looks like this:

C#
"loginUserName=" + usrnm + "&loginUserPassword=" + pswrd + "&autoLogin=on&loginFormSubmit=Login";



and


C#
(HttpWebRequest)HttpWebRequest.Create("http://fileserve.com/login.php");



still no success,
maybe I'm missing something?
Posted
Updated 31-Oct-11 14:33pm
v2

1 solution

To test the error type, you need to include HttpResponse object from System.Web namespace. HttpResponse has StatusCode property. Based on the value, you can confirm the error type.
100 Continue
200 OK
201 Created
300 Multiple Choices
301 Moved Permanently
302 Found
400 Bad Request
401 Unauthorized
403 Forbidden
404 Not Found

C#
protected void Page_Load(object sender, EventArgs e)
{
    switch (Response.StatusCode)
    {
        case 100 : ....; break;
        case 200 : ....; break;
        case 300 : ....; break;
        ........
    }
}
 
Share this answer
 
Comments
Prince_ 1-Nov-11 7:44am    
tried it with :
MessageBox.Show(res.StatusCode.ToString());

The Result was: OK
but I didnt login

OK I think the Problem is that when I normaly Login to Fileserve I get a message that I am getting redirected and have to wait a few seconds before I can access the account,
how Do I let the app wait a little before getting te page I want?
Thread.sleep() doesnt work
Jason Pezzimenti 5-Feb-18 6:06am    
I believe you need to use request.AllowAutoRedirect = true; This will allow redirects to occur, so it should log you in once it has redirected.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900