/// <summary>
        /// 
        /// MOVED the requesting to a new thread and added the callBack error
        /// 
        /// </summary>
        /// <param name="request"></param>
        /// <param name="callBack">response null if exception. exception null otehrwise</param>
        /// <returns></returns>
        public Thread sendRequestAsync(HttpRequest request, AwaitMessageCallback callBack)
        {
            Thread listenThread;
            listenThread = new Thread(() =>
            {
                try
                {
                    request.addHeader("Host", servername);

                    string thisstring = request.ToString();
                    string sendme = request.ToString();
                    byte[] outBytes = Encoding.UTF8.GetBytes(sendme);

                    //try catch here with a fail callback and timeout timer
                    stream.Write(outBytes, 0, outBytes.Length);
                    stream.Flush();
                }
                catch (Exception ex)
                {
                    callBack(null, ex);
                    return;
                }
                callBack(awaitMessage(), null); //Call back should not catch errors
            });
            listenThread.Start();
            return listenThread;
        }
        public HttpResponse sendRequest(HttpRequest request)
        {
            request.addHeader("Host", servername);
            string thisstring = request.ToString();
            string sendme = request.ToString();
            byte[] outBytes = Encoding.UTF8.GetBytes(sendme);
            //stream.Flush();
            stream.Write(outBytes, 0, outBytes.Length);
            stream.Flush();

            return awaitMessage();
        }
예제 #3
0
 static void SignLoginRequest(HttpRequest request)
 {
     request.addHeader("Host", "cas.rowan.edu");
     request.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
 }
예제 #4
0
        static void contact_rowan()
        {
            Boolean logged_in = false;
            HttpBrowserEntitiy browser = new HttpBrowserEntitiy();
            // Secure connections use SSL/TLS
            HttpConnection CAS_Con = browser.openSecureConnection("cas.rowan.edu", HttpBrowserEntitiy.PORTS.SSL, "cas.rowan.edu");
            var request = new HttpRequest("/cas/login");
            SignLoginRequest(request);
            WriteToFile(request.ToString());
            var response = CAS_Con.sendRequest(request);
            browser.processResponse(response);
            browser.SessionCookies.Remove("Path");
            WriteToFile(response.ToString());
            WriteToFile("");
            string resp = response.ToString();
            string lp = GetMiddleString(resp, "name=\"lt\" value=\"", "\" />");
            //WriteToFile(lp);
            //&execution = e4s1 & _eventId = submit & submit = LOGIN
            if (1 == 1)
            {
                request = new HttpRequest("POST", "/cas/login;jsessionid=" + browser.SessionCookies["JSESSIONID"]);
                request.cookies = browser.SessionCookies;
                SignLoginRequest(request);
                request.addHeader("Content-Type", "application/x-www-form-urlencoded");
                //"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"
                Console.Write("Enter Rowan Username: "******"username", Console.ReadLine());
                Console.Write("\r\nEnter Password(NOT HIDDEN): ");
                request.addPost("password", Console.ReadLine());
                request.addPost("lt", lp);
                request.addPost("execution", "e1s1");
                request.addPost("_eventId", "submit");
                request.addPost("submit", "LOGIN");
                request.guessContentLength();
                //WriteToFile(request.ToString());//  LETS NOT SEE EACHOTHER PASSWORD YES?!
                response = CAS_Con.sendRequest(request);
                WriteToFile(response.ToString() + Environment.NewLine);
                browser.processResponse(response);
                browser.SessionCookies.Remove("Path");

                if (response.Body.Contains(SUCCESS_STR))
                {
                    showMessage("You have logged in successfully.");
                    logged_in = true;
                }
                else
                {
                    showMessage("Login Failure!");
                    logged_in = false;
                }
            }
            if (logged_in)
            {
                showMessage("Press any key to log out.");
            }
            else
            {
                showMessage("Press enter to end.");
            }
            Console.Read();
            if (logged_in)
            {
                request = new HttpRequest("/cas/logout");
                SignLoginRequest(request);
                request.cookies = browser.SessionCookies;
                WriteToFile(request.ToString() + Environment.NewLine);
                response = CAS_Con.sendRequest(request);
                WriteToFile(response.ToString());

                if (response.Body.Contains(SUCCESS_STR))
                {
                    showMessage("You have logged in successfully.");
                }
                else
                {
                    showMessage("Error loggin out. This is weird..");
                    Console.Read();
                }
            }
        }
예제 #5
0
 static void Main(string[] args)
 {
     if (args.Length >= 0)
     {
         HttpBrowserEntitiy browser = new HttpBrowserEntitiy(true);
         HttpConnection CAS_Con = browser.openSecureConnection("10.0.0.67", HttpBrowserEntitiy.PORTS.SSL, "lamp");
         var request = new HttpRequest("POST", "/check_cas_auth.php");
         request.addHeader("Content-Type", "application/x-www-form-urlencoded");
         Console.Write("Enter Rowan Username: "******"username", Console.ReadLine());
         Console.Write("\r\nEnter Password(NOT HIDDEN): ");
         request.addPost("password", Console.ReadLine());
         request.guessContentLength();
         //WriteToFile(request.ToString());
         var response = CAS_Con.sendRequest(request);
         WriteToFile(response.Body);
         Console.Read();
     }
     else
     {
         contact_rowan();
     }
 }