none
authorization website RRS feed

  • Question

  • Why I can not authorized on website
    namespace ConsoleApplication1
    {
        class Program
        {
            static void Main(string[] args)
            {
                try
                {
                    HttpWebRequest authReq = (HttpWebRequest)WebRequest.Create("http://login.torrents.ru/forum/login.php");
                    authReq.Timeout = 5000;
                    authReq.Method = "POST";
                    authReq.CookieContainer = new CookieContainer();
                    authReq.AllowAutoRedirect = true;
                    string paramReg = string.Format("redirect={3}&login_username={0}&login_password={1}&login={2}", HttpUtility.UrlEncode("111"), HttpUtility.UrlEncode("222"), HttpUtility.UrlEncode("Вход"), HttpUtility.UrlEncode("index.php"));
                    byte[] POST_Q = ASCIIEncoding.ASCII.GetBytes(paramReg);
                    authReq.ContentLength = POST_Q.Length;
                    authReq.GetRequestStream().Write(POST_Q, 0, POST_Q.Length);
                    authReq.GetRequestStream().Close();
     
                    HttpWebResponse regResponse = (HttpWebResponse)authReq.GetResponse();
     
                    Console.WriteLine(regResponse.ResponseUri.ToString());
                    Console.ReadKey();
                }
                catch (WebException ee)
                {
                    Console.WriteLine(ee.Message);
                }
            }
        }
    }
    What's wrong?
    Wednesday, February 17, 2010 12:45 PM

Answers

  • Hi,

    Did you try to manually fill up the login form with the user credential information to see if it's working?

    If yes, then this might due to your string format is incorrect, in this case you can consider to use webClient to post the data something like:
    Console.Write("\nPlease enter the URI to post data to : ");
    string uriString = Console.ReadLine();
    
    // Create a new WebClient instance.
    WebClient myWebClient = new WebClient();
    
    // Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
    NameValueCollection myNameValueCollection = new NameValueCollection();
    
    Console.WriteLine("Please enter the following parameters to be posted to the URL");
    Console.Write("Name:");
    string name = Console.ReadLine();
    
    Console.Write("Age:");
    string age = Console.ReadLine();
    
    Console.Write("Address:");
    string address = Console.ReadLine();
    
    // Add necessary parameter/value pairs to the name/value container.
    myNameValueCollection.Add("Name",name);            
    myNameValueCollection.Add("Address",address);
    myNameValueCollection.Add("Age",age);
    
    Console.WriteLine("\nUploading to {0} ...",  uriString);
    // 'The Upload(String,NameValueCollection)' implicitly method sets HTTP POST as the request method.            
    byte[] responseArray = myWebClient.UploadValues(uriString,myNameValueCollection);
    
    // Decode and display the response.
    Console.WriteLine("\nResponse received was :\n{0}",Encoding.ASCII.GetString(responseArray));
    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Wednesday, February 24, 2010 2:00 AM
    Monday, February 22, 2010 3:21 AM

All replies

  • Are you sure that this the right format to POST?
    I just tried fiddler and saw that there is one more item in the POST:

    redirect=index.php&login_username=111&login_password=222&ses_short=1 &login=WhatEver

    Noam B
    _________________________________________________________

    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...
    Wednesday, February 17, 2010 1:04 PM
  • HttpAnalyzer has not shown it parametre ses_short=1 !

    All the same does not work
    Wednesday, February 17, 2010 1:16 PM
  • perhaps they are inspecting the header and detecting that your app is not a browser.
    jon.stromer.galley
    Wednesday, February 17, 2010 4:55 PM
  • And if this is the situation you can fix it by adding a line like:
    req.UserAgent = "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 5.1; Trident/4.0; GTB6.3; .NET CLR 2.0.50727; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729)";

    Noam B
    _________________________________________________________

    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...


    Wednesday, February 17, 2010 5:09 PM
  • I don't think so...
    Thursday, February 18, 2010 1:46 AM
  • Hi,

    Did you try to manually fill up the login form with the user credential information to see if it's working?

    If yes, then this might due to your string format is incorrect, in this case you can consider to use webClient to post the data something like:
    Console.Write("\nPlease enter the URI to post data to : ");
    string uriString = Console.ReadLine();
    
    // Create a new WebClient instance.
    WebClient myWebClient = new WebClient();
    
    // Create a new NameValueCollection instance to hold some custom parameters to be posted to the URL.
    NameValueCollection myNameValueCollection = new NameValueCollection();
    
    Console.WriteLine("Please enter the following parameters to be posted to the URL");
    Console.Write("Name:");
    string name = Console.ReadLine();
    
    Console.Write("Age:");
    string age = Console.ReadLine();
    
    Console.Write("Address:");
    string address = Console.ReadLine();
    
    // Add necessary parameter/value pairs to the name/value container.
    myNameValueCollection.Add("Name",name);            
    myNameValueCollection.Add("Address",address);
    myNameValueCollection.Add("Age",age);
    
    Console.WriteLine("\nUploading to {0} ...",  uriString);
    // 'The Upload(String,NameValueCollection)' implicitly method sets HTTP POST as the request method.            
    byte[] responseArray = myWebClient.UploadValues(uriString,myNameValueCollection);
    
    // Decode and display the response.
    Console.WriteLine("\nResponse received was :\n{0}",Encoding.ASCII.GetString(responseArray));
    Thanks
    Binze
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    • Marked as answer by Bin-ze Zhao Wednesday, February 24, 2010 2:00 AM
    Monday, February 22, 2010 3:21 AM