Example #1
0
        /*
         * This is the method that parses the page and collects the cookie form the response.
         *
         * Returns 'true' if the response was processed successfully, otherwise 'false'
         */
        protected bool processLoginResponse(HttpWebResponse loginResp, Encoding encode)
        {
            bool returnVal = false;

            //_cookies = getCookieCollection( loginResp.Headers.Get(HttpResponseHeader.SetCookie.ToString()) );

            _cookies = getCookieCollection(loginResp.Headers.GetValues("Set-Cookie"));

            string responseBody = HelperStatics.convertResponseStream(loginResp.GetResponseStream(), encode);

            // Check to make sure that the response has the data needed for the post
            // Needed data is:
            //     cookie
            //     adapterID
            //     loginPostURL
            if (_cookies != null && _cookies.Count > 0)
            {
                _loginPostURI = getPostUri(responseBody);

                if (_loginPostURI != null && _loginPostURI.Length > 0)
                {
                    _adapterId = getAdapterValue(responseBody);

                    if (_adapterId != null && _adapterId.Length > 0)
                    {
                        returnVal = true;
                    }
                    else
                    {
                        returnVal = false;

                        _processingMessage = buildProcessMessage("Processing Login Page", loginResp.StatusCode.ToString(), responseBody);
                    }
                }
                else
                {
                    returnVal = false;

                    _processingMessage = buildProcessMessage("Processing Login Page", loginResp.StatusCode.ToString(), responseBody);
                }
            }
            else
            {
                returnVal = false;

                _processingMessage = buildProcessMessage("Processing Login Page", loginResp.StatusCode.ToString(), responseBody);
            }

            return(returnVal);
        }
Example #2
0
        /*
         * This method will make the request for the Login page based on the Client ID and then
         * process the Login Page response.
         *
         * Returns 'true' if the page was loaded and the response was processed, otherwise 'false'
         */
        public bool processLoginPage()
        {
            bool retVal = false;

            HttpWebRequest loginReq = (HttpWebRequest)WebRequest.Create(_loginPageURI);

            loginReq.UserAgent = "API Early Adopter - Test Client v1.0 - [email protected]";

            loginReq.AllowAutoRedirect = false;

            HttpWebResponse loginResp = (HttpWebResponse)loginReq.GetResponse();

            if (loginResp.StatusCode == HttpStatusCode.OK)
            {
                retVal = processLoginResponse(loginResp, Encoding.UTF8);
            }
            else if (loginResp.StatusCode == HttpStatusCode.Found)
            {
                retVal = false;

                _processingMessage = buildProcessMessage("Processing Login Page", loginResp.StatusCode.ToString(), "Location is:  " + loginResp.Headers["Location"]);
            }
            else
            {
                retVal = false;

                _processingMessage = buildProcessMessage("Processing Login Page", loginResp.StatusCode.ToString(), HelperStatics.convertResponseStream(loginResp.GetResponseStream(), Encoding.UTF8));
            }

            loginResp.Close();

            return(retVal);
        }
        /*
         * This method will request an Authorization Code by POSTing the Login Page information and credentials then
         * process the response.
         *
         * Returns 'true' if the request completed successfully and the response was processed, otherwise 'false'
         */
        public bool retrieveAuthCode()
        {
            bool retVal = false;

            HttpWebRequest loginPost = (HttpWebRequest)WebRequest.Create(_page.LoginPostURI);

            loginPost.Method = "POST";

            // prepare the headers
            loginPost.Headers.Add("Authorization", _basicAuthValue);
            loginPost.UserAgent         = "API Early Adopter - Test Client v1.0 - [email protected]";
            loginPost.Referer           = _page.LoginPageURI;
            loginPost.AllowAutoRedirect = false;
            loginPost.ContentType       = "application/x-www-form-urlencoded";
            loginPost.CookieContainer   = new CookieContainer();
            loginPost.CookieContainer.Add(new Uri(LoginPage.AUTH_DOMAIN), _page.Cookies);

            // prepare the post data
            byte[] postData = buildLoginPostBody(Encoding.UTF8);
            loginPost.ContentLength = postData.Length;

            Stream dataStream = loginPost.GetRequestStream();

            dataStream.Write(postData, 0, postData.Length);

            dataStream.Close();

            HttpWebResponse loginPostResp = (HttpWebResponse)loginPost.GetResponse();

            if (loginPostResp.StatusCode == HttpStatusCode.OK)
            {
                retVal = false;

                _processingMessage = buildProcessMessage("Posting Login Data", loginPostResp.StatusCode.ToString(), HelperStatics.convertResponseStream(loginPostResp.GetResponseStream(), Encoding.UTF8));
            }
            else if (loginPostResp.StatusCode == HttpStatusCode.Found)
            {
                retVal = processLoginPostResponse(loginPostResp, Encoding.UTF8);

                _processingMessage = buildProcessMessage("Posting Login Data", loginPostResp.StatusCode.ToString(), "Location is:  " + loginPostResp.Headers["Location"] + "\r\n\r\n" + HelperStatics.convertResponseStream(loginPostResp.GetResponseStream(), Encoding.UTF8));
            }
            else
            {
                retVal = false;

                _processingMessage = buildProcessMessage("Posting Login Data", loginPostResp.StatusCode.ToString(), HelperStatics.convertResponseStream(loginPostResp.GetResponseStream(), Encoding.UTF8));
            }

            loginPostResp.Close();

            return(retVal);
        }