示例#1
0
        internal static string PerformAuthentication(Resources context)
        {
            AcsResponse param       = new AcsResponse();
            BrowserForm browserForm = new BrowserForm(aosUrl, param);

            WindowsForms.Application.Run(browserForm);
            // Debug.Assert(!browserForm.NavigationCanceled, "Unable to perform authentication to AOS");

            HttpWebRequest  httpRequest;
            HttpWebResponse httpResponse;
            CookieContainer cookieContainer = new CookieContainer();

            httpRequest             = (HttpWebRequest)WebRequest.Create(aosUrl);
            httpRequest.Method      = "POST";
            httpRequest.ContentType = "application/x-www-form-urlencoded";

            //
            // Authentication was done by using the hostname URI and not
            // full request URI. Hence, we should not let autoredirect
            // happen.
            //

            httpRequest.AllowAutoRedirect = false;
            httpRequest.CookieContainer   = cookieContainer;

            StreamWriter writer = new StreamWriter(httpRequest.GetRequestStream(), Encoding.ASCII);

            writer.Write(param.GetAcsResponseString());
            writer.Flush();
            writer.Close();

            httpResponse = (HttpWebResponse)httpRequest.GetResponse();
            httpResponse.Close();

            StringBuilder retval = new StringBuilder();

            CookieCollection cookiesCollection = cookieContainer.GetCookies(new Uri(aosUrl));

            if (cookiesCollection.Count > 0)
            {
                foreach (Cookie c in cookiesCollection)
                {
                    retval.AppendFormat("{0}={1}; ", c.Name, c.Value);
                }

                //Remove the trailing "; "
                retval.Remove(retval.Length - 2, 2);
            }

            cookies = retval.ToString();

            context.SendingRequest += new EventHandler <SendingRequestEventArgs>(OnSendingRequest);

            return(cookies);
        }
示例#2
0
 private void SetAcsResponseParam(AcsResponse param)
 {
     m_acsResponseParam = param;
 }
示例#3
0
 public BrowserForm(String url, AcsResponse param)
 {
     SetUrl(url);
     SetAcsResponseParam(param);
     InitializeComponent();
 }