コード例 #1
0
        private WebResponse GetWebResponseViaPostMethod(Uri requestUri, Dictionary <string, string> postVariables, string referer, bool allowRedirect)
        {
            try
            {
                WebClientRequestManager.WaitWhileMaxSimultaneousRequestIsReached();
                WebResponse response;
                Exception   exception         = null;
                bool        submitCredentials = false;

                do
                {
                    submitCredentials = false;
                    HttpWebRequest httpRequest = PreparePostRequest(requestUri, allowRedirect, referer);
                    string         postString  = dictionaryToPostString(postVariables);
                    byte[]         postData    = Encoding.ASCII.GetBytes(postString);
                    response = SendPostRequest(httpRequest, postData, out exception);
                    ParseWebException(response, exception, requestUri, out submitCredentials);
                } while (submitCredentials);

                return(response);
            }
            finally
            {
                WebClientRequestManager.ReleaseMaxRequestLockWait();
            }
        }
コード例 #2
0
        public string PostSynchronous(Uri requestUri, string postString, string referer, bool allowRedirect, bool checkSessionStatus)
        {
            try
            {
                WebClientRequestManager.WaitWhileMaxSimultaneousRequestIsReached();
                WebResponse response;
                Exception   exception         = null;
                bool        submitCredentials = false;

                do
                {
                    HttpWebRequest httpRequest = PreparePostRequest(requestUri, allowRedirect, referer);
                    byte[]         postData    = Encoding.ASCII.GetBytes(postString);
                    response = SendPostRequest(httpRequest, postData, out exception);
                    ParseWebException(response, exception, requestUri, out submitCredentials);
                } while (submitCredentials);

                return(ReadResponseContent(response, checkSessionStatus));
            }
            catch (Exception ex)
            {
                OnLogWebClientException(requestUri, ex);
                return(Constants.ERROR);
            }
            finally
            {
                WebClientRequestManager.ReleaseMaxRequestLockWait();
            }
        }
コード例 #3
0
        public string GetPage(Uri requestUri, string referer, bool allowRedirect, bool checkSessionStatus)
        {
            try
            {
                WebClientRequestManager.WaitWhileMaxSimultaneousRequestIsReached();
                HttpWebRequest httpRequest;
                WebResponse    response;
                Exception      exception         = null;
                bool           submitCredentials = false;

                if (!string.IsNullOrEmpty(_userName) && !string.IsNullOrEmpty(_password))
                {
                    allowRedirect = false;
                }

                do
                {
                    httpRequest = PrepareGetRequest(requestUri, allowRedirect, referer);
                    response    = SendGetRequest(httpRequest, out exception);
                    ParseWebException(response, exception, requestUri, out submitCredentials);
                } while (submitCredentials);

                //if (response != null && response.Headers != null && response.Headers["Location"] != null && response.Headers["Location"].Length > 0)
                //{
                //    do
                //    {
                //        response.Close();
                //        Uri location = GetRedirectLocation(requestUri, response.Headers["Location"].ToString());
                //        response = null;
                //        httpRequest = PrepareGetRequest(location, allowRedirect, referer);
                //        response = SendGetRequest(httpRequest, out exception);
                //        ParseWebException(response, exception, requestUri, out submitCredentials);
                //    } while (submitCredentials);
                //}

                // Debug
                //if (response != null && response.Headers != null && response.Headers["Location"] != null && response.Headers["Location"].Length > 0)
                //{
                //    Uri location = GetRedirectLocation(requestUri, response.Headers["Location"].ToString());
                //    MessageBox.Show(location.AbsoluteUri, "Redirection", MessageBoxButtons.OK);
                //}

                return(ReadResponseContent(response, checkSessionStatus));
            }
            catch (Exception ex)
            {
                OnLogWebClientException(requestUri, ex);
                return(Constants.ERROR);
            }
            finally
            {
                WebClientRequestManager.ReleaseMaxRequestLockWait();
            }
        }
コード例 #4
0
        public string GetPage(Uri requestUri, string referer, bool checkSessionStatus)
        {
            try
            {
                RequestDefaultUri();
                WebClientRequestManager.WaitWhileMaxSimultaneousRequestIsReached();
                HttpWebRequest httpRequest;
                WebResponse    response;
                Exception      exception         = null;
                bool           submitCredentials = false;

                do
                {
                    httpRequest = PrepareGetRequest(requestUri, false, referer);
                    response    = SendGetRequest(httpRequest, out exception);
                    ParseWebException(response, exception, requestUri, out submitCredentials);
                } while (submitCredentials);

                if (response != null && response.Headers != null && response.Headers["Location"] != null && response.Headers["Location"].Length > 0)
                {
                    do
                    {
                        response.Close();
                        Uri location = GetRedirectLocation(requestUri, response.Headers["Location"].ToString());
                        response    = null;
                        httpRequest = PrepareGetRequest(location, false, referer);
                        response    = SendGetRequest(httpRequest, out exception);
                        ParseWebException(response, exception, requestUri, out submitCredentials);
                    } while (submitCredentials);
                }

                return(ReadResponseContent(response, checkSessionStatus));
            }
            catch (Exception ex)
            {
                OnLogWebClientException(requestUri, ex);
                return(Constants.ERROR);
            }
            finally
            {
                WebClientRequestManager.ReleaseMaxRequestLockWait();
            }
        }
コード例 #5
0
        ///// <summary>
        ///// Post data must be included in the requestUri.
        ///// E.g. http://www.domain.com/index.php?page=home&lang=en
        ///// Post data will be extracted and send via POST.
        ///// </summary>
        ///// <param name="requestUri"></param>
        ///// <param name="referer"></param>
        ///// <param name="allowRedirect"></param>
        ///// <param name="checkSessionStatus"></param>
        ///// <returns></returns>
        //public string PostSynchronous(Uri requestUri, string referer, bool allowRedirect, bool checkSessionStatus)
        //{
        //    HttpWebRequest httpRequest = PreparePostRequest(requestUri, allowRedirect, referer);
        //    byte[] postData = Encoding.ASCII.GetBytes(Utilities.GetPostStringFromUri(requestUri));
        //    return ReadResponseContent(SendPostRequest(httpRequest, postData), checkSessionStatus);
        //}

        private WebResponse GetWebResponseViaGetMethod(Uri requestUri, string referer, bool allowRedirect)
        {
            try
            {
                WebClientRequestManager.WaitWhileMaxSimultaneousRequestIsReached();
                WebResponse response;
                Exception   exception         = null;
                bool        submitCredentials = false;

                do
                {
                    HttpWebRequest httpRequest = PrepareGetRequest(requestUri, allowRedirect, referer);
                    response = SendGetRequest(httpRequest, out exception);
                    ParseWebException(response, exception, requestUri, out submitCredentials);
                } while (submitCredentials);

                return(response);
            }
            finally
            {
                WebClientRequestManager.ReleaseMaxRequestLockWait();
            }
        }